Hey guys. I haven't been here for a long time. Reason being that I didn't really code in that time. Now I've returned to my project and ran into some problem.
Last time I've worked on it, I've switched my physics engine from bullet to jitter due to unresolvable problems, but there's now an issue with my steering code.
In essence, depending on what direction I'm facing relative to the initial orientation the actual change in direction differs more or less from the actual input.
For example, I'f I turn 90 degrees left or right it becomes impossible to turn up or down.
Now, in order to make the spaceship turn, this is the code for it:
Within InputSystem I calculate cursor offset from the screen center and then from it a multiplier that is then used by MovementSystem:
var mouseOffsetMagnitude = Math.Abs(_mouseOffset.Length());
if(mouseOffsetMagnitude < 10)
rot.TurnMultiplier = Vector3.Zero;
else if (mouseOffsetMagnitude > _screenCenter.Y*0.8)
{
rot.TurnMultiplier = Vector3.Zero;
}
else
{
var multiX = _mouseOffset.X/(_screenCenter.Y*0.8);
var multiY = _mouseOffset.Y/(_screenCenter.Y*0.8);
rot.TurnMultiplier = new Vector3((float) multiY, (float) -multiX, 0);
}
MovementSystem takes this multiplier, which is then multiplied by the ships steering torque and a constant to get the torque vector for steering. The torque vector is also transformed by the ships orientation to ensure it's facing the correct way and then fed into Jitter to make the ship actually turn:
var torqueVector = Vector3.Transform(rot.TurnMultiplier*phys.SteeringTorque*0.00025f, body.Orientation.FromJMatrix());
body.AddTorque(new JVector(0.0f, torqueVector.Y, -torqueVector.X));
Currently roll is not used, hence the 0 value in the last line.
↧