|||| 8 - 15 nov 2014 ||||
7DFPS ...
solution to south pole madness! (in unity)
I've been going crazy trying to find a solution to "south pole madness", and once I found some threads where someone was calling it that, I found a solution! Here's the thread where I found the answer: http://forum.unity3d.com/threads/question-about-quaternions.3671/ And here's the problem: If you're making a game where a character is walking on the surface of a sphere like in Mario Galaxy, you turn off "standard" gravity, and set gravity instead as a force that pulls the character toward the center of the sphere. So far so good. Now, to make sure the character is always standing upright, my first inclination was to set the character's transform.up to the inverse of the direction of the gravity force. So, if my planet's center was at the origin, my gravity force would be: -transform.position.normalized * 9.8f and my transform.up would be: transform.up = transform.position.normalized; However!! when you do this, it nudges your Y rotation toward the south pole, and the closer you get to the south pole the stronger the nudge is, to the point that on the southern hemisphere moving the character forward spirals it toward the south pole, and when the character reaches the south pole trying to move forward just spins it wildly in place. I found that if I turned off the assignment to "transform.up" it would move correctly, but then, of course, my character would not stay upright. So!! I knew the culprit was that transform.up assignment, and the solution would be to make my own damn up, but I couldn't figure out how to do so (because I'm lazy and keep putting off teaching myself Linear Algebra). I finally found the solution at the link above, and here's what I implemented: in place of: transform.up = transform.position.normalized; I added: Vector3 MyForward = Vector3.Cross(transform.right, transform.position.normalized); transform.rotation = Quaternion.LookRotation(MyForward, transform.position.normalized); and hooray!!! Everything works now!!! (Note that, for the sake of clarity, I wrote everything here as though I were making a Mario-Galaxy-style game where the character is running on the outer surface of a sphere, because I thought that would be a more common implementation. In my game, the character is actually running on the inner surface of a sphere, so every "transform.position.normalized" in the code samples above is actually "-transform.position.normalized" in my game, but the principle is the same.)
7DFPS brought to you by Sven Bergstrom & Sos Sosowski & Jan Willem Nijman | Logo by Cactus Follow news and info about 7DFPS on twitter Games hosted on itch.io