# Spaceship steering based on mouse offset

This topic is 957 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## 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 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 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.

1. 1
2. 2
Rutin
19
3. 3
4. 4
5. 5

• 13
• 26
• 10
• 11
• 9
• ### Forum Statistics

• Total Topics
633736
• Total Posts
3013598
×