godot_recipes icon indicating copy to clipboard operation
godot_recipes copied to clipboard

[Discussion] 3D: Shooting projectiles

Open cbscribe opened this issue 5 years ago • 5 comments

Discussion for http://godotrecipes.com/3d/3d_shooting/

cbscribe avatar Feb 03 '21 02:02 cbscribe

We fire the whole bullet. That's 60% more bullet per bullet.

sshelton avatar Feb 24 '21 18:02 sshelton

So I'm using the FPS character you showed how to make here

And i tried to add a trajectory, (make the shotgun able to shoot bullets) and i followed this tutorial here

Everything is done correctly as far as i can tell except that when i play the game and left click it stops the game and says

Invalid call. Nonexistant function 'instance' in base 'Nil'

And points to var b = Bullet.instance()

    extends MeshInstance
    export (PackedScene) var Bullet

     func _unhandled_input(event):
	      if Input.is_action_just_pressed("shoot"):
		   var b = Bullet.instance()
		   owner.add_child(b)
	           b.transform = $Shotgun/Muzzle.global_transform
		   b.velocity = -b.transform.basis.z * b.muzzle_velocity

Any ideas? Thanks in advance!

AnarchyEnthusiast avatar Feb 17 '22 18:02 AnarchyEnthusiast

@CodingPsych disclaimer- still learning - but (I understand) export (PackedScene) var Bullet needs to point to an actual scene. That's why it says Nonexistent. I think you need to add the path to the scene something like export (PackedScene) var Bullet = preload("res://BulletScene.tscn")

replace BulletScene with the actual bullet scene name from your project

Or drag that BulletScene path from Filesystem over to the INSPECTOR->SCRIPT VARIABLES-> "Bullet" variable entry box - AFTER SAVE but PRIOR to running the script. I am guessing it is empty now.

I recommend initialize with preload - It is is better coding practice to always initialize variables to some known state and not leave them null hoping you remember to set them in the Inspector - as well as NOT inadvertently deleting later.

dchennault avatar Feb 20 '22 22:02 dchennault

http://kidscancode.org/godot_recipes/files/3d_shooting.zip This link is not available anymore. It show 404 error. Can you update it please??

habibsyuhada avatar Feb 28 '22 06:02 habibsyuhada

Our boys down in science, well, they know how to fill stuff with bullets. Drop a couple of those into a pneumatic piston and it fires the whole shell. That's sixty per-cent more bullet per bullet. I punch those numbers into my calculator and it makes a happy face.

DriftWare07 avatar Jul 29 '22 14:07 DriftWare07