[Discussion] 3D: Shooting projectiles
Discussion for http://godotrecipes.com/3d/3d_shooting/
We fire the whole bullet. That's 60% more bullet per bullet.
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!
@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.
http://kidscancode.org/godot_recipes/files/3d_shooting.zip This link is not available anymore. It show 404 error. Can you update it please??
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.