I'm making an Asteroids clone. When the player presses spacebar, the player's ship shoots a bullet. I want the bullet to inherit the velocity of the ship, as well as moving forward like a bullet does.
I've tried simply copying the velocity of the ship into the bullet when the bullet is created:
const MOVE_SPEED = 7
var vel = Vector2()
# inherit player velocity
vel = get_node("/root/bg-root/game-root/player").get_linear_velocity()
# add bullet velocity
# vel += Vector2(sin(get_rot()), cos(get_rot()))
move(-vel) # negate to move aligned with sprite
For now I've commented out the line where I add the bullet's velocity, because I want to make sure I'm getting the ship's velocity correct first.
What happens is the bullet moves several times faster than the ship does. I've used print statements and the debugger and I've verified that the velocity being passed to the bullet is the same as the velocity of the ship. The bullet is added as a sibling of the ship, not a child, so its velocity should be relative to world space. The ship is a RigidBody2D, while the bullet is a KinematicBody2D, but I wouldn't think that makes any difference.
FWIW the velocity is typically in the range of 50 - 100 for both parts of the vector2, and I don't know what units it's supposed to be in but it seems high. Anyways, it shouldn't matter, if that's the velocity of the ship, then it should act the same on the bullet.
So, what's happening?