Cannon barrel recoil?
Hello, I have programmed a turret cannon node that will rotate and has rotation limits. I am trying to add a recoil function so it will the barrel will recoil along its axis and then return. It is simply two nodes the barrel and the base that are siblings in a cannon container node(area2d's with a sprite).
I have a function that will recoil and return the barrel but when the barrel is rotated it just moves the barrel up and down.
if is_recoiling == false:
$cannon_barrel.translate(Vector2(0,RECOIL_SPEED * delta_time))
if $cannon_barrel.get_position().y > MAX_RECOIL:
is_recoiling = true
elif is_recoiling == true:
$cannon_barrel.translate(Vector2(0,-RECOIL_SPEED * delta_time))
if $cannon_barrel.get_position().y < RETURN_POSITION:
is_recoiling = false
I call this in the process function. I can see the problem is just moving the y coordinate relative to the parent down and up. What function will move the y back along its own axis?