I needed a way to make a bullet but i have no idea what node to use i was using a kinematic body but im having all sorts of problems such as firing it and others. Thanks in advance
Whats the best way to make a bullet?
- Edited
Use RigidBody instead.
Make a bullet scene that has your bullet image and a script like below. In your player node or other node, connect the hit() signal to a function that determines whether the bullet should do damage or not. Instantiate a bullet scene, determine the location you want to spawn it(e.g. end of gun) and the direction you want it to travel and make this a matrix. Pass this matrix to the shoot() function in the bullet.
Basic example, but I think it should give you a good starting point. Let me know if this works for you.
extends RigidBody2D
var damage = 10
var vel = Vector2(100,0)
signal hit(body, damage)
func _ready():
set_fixed_process(true)
set_contact_monitor(true)
set_max_contacts_reported(1)
connect("body_enter", self, "contact")
func _fixed_process(delta):
pass
func shoot(var matrix):
set_transform(matrix)
set_linear_velocity(vel)
func contact(body):
if body.is_in_group("Enemy"):
emit_signal("hit", body, damage)
destroy()
func destroy():
#play explosion animation and sound
queue_free()
func _on_Timer_timeout():
#Destroy after short time in case it never hits anything
destroy()
*editted Vector2D, some typos, and function argument order**
https://godotengine.org/download
Download the demo examples, there's a couple that show how to do 2D bullets -'Platformer' and 'Space Shooter'.