Space Flight Simulator Turning Problems
Hello.
I am working on a game that involves travel in space, and I am trying to make a flight simulator.
I have it so the space button accelerates ( Rigidbody.AddRelativeForce(0,0,bla*acceleration);
) your ship forwards (z-axis, wherever z is facing based on the particular rotation at that time). I also have it where if you right click, you can move your spaceship in the direction of your mouse (with Rigidbody.AddRelativeTorque (Input.GetAxis("Mouse X"*accelerationTurn, Input.GetAxis("Mouse Y")*accelerationTurn, 0);
).
This is the problem. Say I right click at the right edge of the screen. Then the mouse's local location becomes (0,0). You turn right too fast, and when you attempt to correct your position, you by default move to the center of the screen and move in the desired direction. The problem is that the real axis is dislocated to the right, and this further dislocates your character because you are still in the left side of the axis when you want to go right. Then, you spiral perpetually and have no means of recovery.
Does anyone have a solution as to how to get the axis always in the center of the screen?
Also, I have a max turn acceleration that I am checking for like this:
if ((ri.angularVelocity.x < maxTurn) && (ri.angularVelocity.x > -maxTurn) && (ri.angularVelocity.y < maxTurn) && (ri.angularVelocity.y > -maxTurn)) {
ri.AddRelativeTorque (x * rateOfTurnAcceleration, y * rateOfTurnAcceleration, 0);
}
So this method of constraining the turn velocity actually does deadlock the system so you just can't turn and do the perpetual spiral of death.
If anyone has an answer for how I should handle these problems, which are really the same problem, I will appreciate and +1.
Thanks.
Your answer
Follow this Question
Related Questions
Input.GetAxis going crazy when I click outside the game window 0 Answers
How can I use both mouse and keyboard to do the same thing? [SOLVED] 1 Answer
Basic character controller not working properly 0 Answers
Why is my Player game object not rotating with mouse movement in 'Survival Shooter' unity project 10 Answers
How to determine the maximum and minimum values of Input.GetAxis("Mouse X")? 1 Answer