Hey there. I'm new here, but already need help with XNA/Monogame (well it's more Math and Phyics in fact).
Im writing a little game for fun and came to some problems regarding calculations.
First a little overview:
The Game is like a little Flight Simulator, with one significant change: The Planet should be a Sphere.
For Pitch and Roll I used Quaternion-Calc (through tutorial, because I'm not that much into Quaternions),
so the ship can Roll and Pitch around its own axis.
I wanted to add some physics into the game, namly upforce and downforce.
For that I want to calculate the relative height first to make the downforce and upforce decrease when going higher till zero.
Question A:
How do I determine the relative Height to the surface?
The Planet is just a Sphere in this state, and I want to make the height over Sea-Level, so there
won't be a Problem when adding Terrain.
My thoughts for a Solution to A:
Could I just calculate the Distance of the Ship to every point of the Planet and pick the one with the
smallest distance? Or would that be a waste of time?
Another approach was to just calc the distance from Point(0,0,0) and subtract the radius of the planet.
Would be much easier then, I think.
I'll go on:
The upforce should not be affected by Roll-Angle but by the Pitch-Angle.
If the Ship goes up on 90° the downforce would be zero, so to say.
Question B:
How do I determine the relative Pitch to Surface?
As I'm not used to Quaternions I just tried out.
When using rotation (quaternion) there is no matter what (rotation.X, rotation.Y, rotation.Z, rotation.Y),
it won't give me the right Angle.
As the Rotation is calculated by pitch-angle (rad) and roll-angle (rad) i tried to use the cos(pitch-angle)
which will work fine as long as the surface is not a sphere and the ship wont roll.
My thoghts for a Solution to B:
My theoretical approach was to use the radius of the planet and building a Tangent on the Sphere on the
nearest position of the ship to the surface in the direction the ship is flying ( or is nearest to when flying upwards).
So to say, the Tangent has the direction that is 90° off to the direction the Wing-Tip goes to.
With this Tangent I could calculate the angle between it and the ships direction.
Question C:
How can I manage it to let the Plane fall to the surface if Downforce is higher than Upforce and both are not Zero?
My thoughts for a Solution on C:
Maybe I could use the Vector between the nearest point on the Sphere to the Ship, normalize it and devide it by a
value that depends on the downforce in regarde of height. Meaning the Normalized Vector will be "unnormalized"
so it gets bigger when getting nearer to the surface.
I won't use air-Resistance as a variable to determine the falling speed so this won't be a Problem.
then i could cange the Position-Vector of the ship to get closer to the surface by the rate of the calculated Vector.
I would appreaciate if anyone has a better solution to this problems or would comment on my approaches so I can
learn from it!
Thank you!
Edit:
Ah I forgot a point in regards of Gravitation:
I don't want to have this hard Physics in the game so I decided to
make a radius in where the Gravitation starts to play.
So to say: if the ship collides with the atmosphere, the gravitation starts to go up.
This makes it a lot easier when having more than 1 planet.