Jump to content
  • Advertisement
scippie

Spaceship controls -> autopilot

Recommended Posts

8 hours ago, scippie said:

What I mean is that quaternions don't work in the yaw/pitch/roll sense. I know you can construct a quaternion from them, but then you could as well be using matrices and have gimbal lock problems.

I'm not sure based on the above whether you're operating under this particular misconception (if not, apologies, and please ignore this), but I'll go ahead and mention that quaternions and matrices don't differ from one another with respect to gimbal lock. You can both encounter and avoid gimbal lock with each, and for the same reasons. (Historically at least there's been a fair amount of confusion about this, so I think it's worth clarifying.)

Share this post


Link to post
Share on other sites
Advertisement
55 minutes ago, Zakwayda said:

I'm not sure based on the above whether you're operating under this particular misconception (if not, apologies, and please ignore this), but I'll go ahead and mention that quaternions and matrices don't differ from one another with respect to gimbal lock. You can both encounter and avoid gimbal lock with each, and for the same reasons. (Historically at least there's been a fair amount of confusion about this, so I think it's worth clarifying.)

Ok, you are right, I have really been expressing myself completely incorrectly. Of course, quaternions and matrices are the same for rotation and can both prevent gimbal lock. What I really meant to say was working with yaw, pitch and roll with a constant reference is different and will also cause gimbal lock.

But, I really do understand it, no worries 🙂

Share this post


Link to post
Share on other sites
Posted (edited)
2 hours ago, scippie said:

Cool! Yes please, share your code! 😉

My quaternion code is here: https://github.com/daid/SeriousProton2/blob/master/include/sp2/math/quaternion.h

Vector3 is also there. Note that my "toAxisAngle()" function multiplies the axis (which is a normalized vector) with the angle (which is the amount of rotation) which is why it can only return a Vector3 instead of returning a Vector3 and a scalar (double) for a proper axis+angle.

My X+ is "forwards" and "Z+" is up. Not sure how much that matters.

Simplified code is then:

Vector3d target_position = ???;

Quaterniond target_rotation = Quaterniond::fromVectorToVector(Vector3d(1, 0, 0), target_position);
Vector3d rotation_required = getRotation3D().diff(target_rotation).toAxisAngle();

double roll = rotation_required.x;
double pitch = rotation_required.y;
double yaw = rotation_required.z;

I limit the roll/pitch/yaw each update, and recalculate the "rotation_required" each update. Due to some damping and acceleration I get a bit of overshoot. But that's due to other things my code is doing as well, I think the math here is sound otherwise.

Edited by Daid

Share this post


Link to post
Share on other sites

Did you try pooling objects that interact with the ship collider at thrust points, the rate of SetActive of the thruster particles, bounce off the collider and cause the ship to move in the opposite direction. I have not tried this solution it may be terribly inefficient and lack stability or control. It may allow for more realistic thrust.

Share this post


Link to post
Share on other sites
1 hour ago, Wcoltd said:

Did you try pooling objects that interact with the ship collider at thrust points, the rate of SetActive of the thruster particles, bounce off the collider and cause the ship to move in the opposite direction. I have not tried this solution it may be terribly inefficient and lack stability or control. It may allow for more realistic thrust.

The thrust in my implementation is fine, it's controlling it on auto-pilot that is the problem.

Share this post


Link to post
Share on other sites
1 hour ago, scippie said:

The thrust in my implementation is fine, it's controlling it on auto-pilot that is the problem.

So you're trying to emulate the same flight characteristics on Autopilot as when you are flying manually? Can you post the code for manual flight? I've got an idea.

Share this post


Link to post
Share on other sites

I am currently looking into a non-mathematical way to solve this problem as it does not really seem to be something that can be solved straightforward.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!