- Home /
Make object lay flat on a sphere + look up?
Looking around I found a youtube video (at https://www.youtube.com/watch?v=gHeQ8Hr92P4) which explained how to make a object, such as a player character, walk around on a sphere while keeping its "head" facing upwards, even if it is on the side or bottom of the "planet".
His code works, but has a problem. The problem is, if I attach the "player" to my mouse, and move it around on the planet surface using my mouse, I notice that even though it DOES stay upright on the planet, it continually changes the direction it is "facing" as I move it around.
Here is the code (it works):
Vector3 gravityUp = (player.position - planet.position).normalized;
Vector3 playerUp = player.up;
var horizontalRotation = Quaternion.FromToRotation (playerUp, gravityUp) * player.rotation;
player.rotation = horizontalRotation;
Alright, so what I need for my current situation is for the "player" to always face towards the north pole of the planet. I created an empty object named "north pole" and put it at the top of my planet.
From there, I tried:
var upRotation = Quaternion.LookRotation(player.position - NorthPole.transform.position);
I then tried to change only the "rotation.y" value of the player, hoping that this would forceably make it look towards the north pole:
horizontalRotation.y = upRotation.y;
body.rotation = horizontalRotation;
This did not work, the player object jerks around. How do I do this?
I need the player to continue to stand upright on the planet, but look towards the north pole always, no matter where I move him to with my mouse.
Just so you know: "player" is just a box mesh, and "planet" is a sphere mesh.
Your answer
Follow this Question
Related Questions
Get slerp to work just as LookAt(,Vector3.right) does 1 Answer
Boids for 2D 0 Answers
Instantiated Objects Point towards unknown point 0 Answers
How to use quaternion.lerp 2 Answers
Rotate object without storing facing 1 Answer