Sign in to follow this  
Stefan Fischlschweiger

Spaceship steering based on mouse offset

Recommended Posts

So, as some of you might have noticed from previous posts I'm working on a space sim sort of game.

 

In the past I've moved to use BulletSharp for physics (mainly for collision ^^)

 

Now I want to get my mouse based steering to work.

 

Basically what I'm doing right now is (pseudocode):

InputSystem
{
    GetMousePosition;
    GetMouseOffsetFromScreenCenter(mousePosition);
    CalculateTurnMultiplier(mouseOffset)

    RotationComponent.turnMulti = turnMulti;
}

MovementSystem
{
    torqueVector = (turnMulti*steeringTorque*scaling) transformed by rigidBody.Orientation
    rigidBody.ApplyTorque(torqueVector);
}

This does turn the ship, but in all kinds of weird ways.

 

The steering behaviour I want is actually like this:

[attachment=31472:spaceshipturning.png]

 

Kind of like in freelancer.

 

Now, I've already figured out on how to get my desired TurnMultiplier (how hard the ship shall turn), but the calculation of the correct torque to put into BulletSharp is giving me headaches.

 

My theory is that, when I move the cursor away from the screen center I need to add more torque based on how fast I'm already turning and vice versa. But this just doesn't want to compute in my head.

Share this post


Link to post
Share on other sites

I've never used BulletSharp, but are you using Euler or Quaternion? If you are making a full 3D space sim, you should be using Quats. DX has built-in quaternion rotation functions so you can use the vector (x,y) from center to rotate "up/down" and "left/right" by the scale of that vector. I hope this helps, because I'm not sure if your question is about rotation or something to do with BulletSharp...... 

Share this post


Link to post
Share on other sites
The simple solution is to not use torque to steer your ship, because torque and angular inertia do weird things as you have discovered.

Most physics engines have a mode or special body type where you can apply "controls" in addition to real physics forces. I haven't touched Bullet in years and have no idea about BulletSharp, but I'd lay odds there's a way to directly set the rotation of your ship. Do the steering computation and any damping/acceleration/etc. you want in the game code, and don't bother trying to replicate that behavior in physics terms.

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

Sign in to follow this