0 votes

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 )

in Engine by (27 points)
edited by

2 Answers

0 votes

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

Usage in your case, probably:

tilt = lerp_angle(tilt, tilt + tilt_lr * ROLL_SPEED, 1)
# or directly
tilt += short_angle_distance(tilt, tilt + tilt_lr * ROLL_SPEED)
by (4,005 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.

0 votes

I've further edited my original post for extra clarity. I hope it makes more sense now.

by (27 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.