I'm working on an on-rails-shooter using the current 3.1 beta, where one of the manoeuvres has the player ship rotate on itself (like a barrel-roll). I can get it to rotate around itself, but it doesn't quite work as planned. This is what it currently looks like in action

Notably: the ship does a full 360* reverse roll back to the 0 position, instead of completing a roll from 270*, or going back to 0 after breaching the initial rotation . Is there a way to force a 360* rotation to be seen as going back to 0 upon going a bit above?

I tried doing something along the lines of this question, but it doesn't work with what I have.

Here's the current code that I'm using for the effect:

`var angles = Vector3()`
`if tilt_lr:`
`> tilt += tilt_lr * TILT_SPEED`
`>> if roll:`
`>>> tilt += tilt_lr * ROLL_SPEED`
`if abs(rotation_degrees.z) >= ROLL_SPEED`
`> tilt += tilt_lr * 0.0`
`var flight_dir = Vector3(pitch,yaw,tilt)`
`angles = angles.linear_interpolate( flight_dir, ROTATE_SPEED * dt )`
`set_rotation_degrees(angles)`

in Engine
edited

Posted this some days ago.
Not sure what exactly you are trying to achieve but I think it could help:

``````func lerp_angle(from, to, weight):
return from + short_angle_dist(from, to) * weight

func short_angle_dist(from, to):
var max_angle = PI * 2
var difference = fmod(to - from, max_angle)
return fmod(2 * difference, max_angle) - difference
``````

``````tilt = lerp_angle(tilt, tilt + tilt_lr * ROLL_SPEED, 1)
# or directly
tilt += short_angle_distance(tilt, tilt + tilt_lr * ROLL_SPEED)
``````
by (4,209 points)

Hey, thanks for the answer. It doesn't seem to help with regards to getting the roll working correctly. I posted a link to its current behaviour in the original post, in case that helps better see what I'm looking to do.

For further clarification: when I look at the output of rotation_degrees.z, it would go up to 180*, and roll back to 0*. I'm thinking that if I can have the degree count be "reset" as it's reaching a certain point, the rotation would complete correctly instead.