Hey everyone, game dev noobie here hoping to get some help adding a barrel roll to my project.
This is my current implementation using lerp, but it only works sometimes... wondering if there's a better way.
var rotation = deg_to_rad(720.0)
ship.rotation.z = lerp(ship.rotation.z, ship.rotation.z+rotation, 0.3)
coll.rotation.z = lerp(coll.rotation.z, coll.rotation.z+rotation, 0.3)```
I also use this when moving left or right to give the ship some lean, which is where the animation kind of falls apart:
``` var direction = Vector3(Input.get_axis("move_left", "move_right"), 0, 0)
velocity = direction * speed
if direction:
last_direction = direction
velocity.z = direction.z * speed
ship.rotation.z = lerp_angle(ship.rotation.z, -atan2(-last_direction.x, -last_direction.z), delta * rotation_speed)
coll.rotation.z = lerp_angle(coll.rotation.z, -atan2(-last_direction.x, -last_direction.z), delta * rotation_speed)
else:
velocity.z = move_toward(velocity.z, 0, speed)
ship.rotation.z = lerp_angle(ship.rotation.z, 0, 0.1)
coll.rotation.z = lerp_angle(ship.rotation.z, 0, 0.1)
move_and_slide()```
I attached a video showing the roll, then moving while rolling, then just moving, then moving while rolling again. I'd love to get to a more consistent solution that rolls regardless of my position, and that I can easily control how many times the ship spins. I'm also planning on adding some "wind" around the character when they spin, so is lerp even the right thing to be using here?