# rotating the bottom of an object to face another player.

i have a script that i use in 2d to rotate something to face the player, and i adapted it to 3d, but in 2d whenever i wanted to change how it was rotated i just changed the direction of the sprite in photoshop, in 3d i cant do that and idk how to get a specific part of the object to be facing the target, for instance i want the player to be able to walk on walls so to orient them i would rotate them to face the wall, but their feet need to be facing the wall, how would i adapt this script to do that

`````` Vector3 Direction = target.transform.position - transform.position;
Quaternion rotation = Quaternion.LookRotation(Direction);
transform.rotation = rotation;
``````

if you want the bottom to face something, you could do:

``````tranform.up = -directionBottomShouldFace
``````

problem is that it only guarantees one axis. you probably want something like

``````transform.LookAt(directionToLookIn, -directionForFeetToPoint)
``````

i didnt even know transform.lookat was a thing lol i probably should have, when experimenting with this i get a similar result, along with some weird results, i tried vector positons such as up down left right forward back, a physical world location, and a local position for the feet to be here is the code i have now

``````  Vector3 Direction = CurrentPlanet.transform.position - transform.position;
// Vector3 FeetPosDir = FeetPos.transform.position - transform.position;
//Quaternion rotation = Quaternion.LookRotation(Direction);
//  tempRotat.rotation = rotation;
transform.LookAt(Direction, CurrentPlanet.transform.position
``````

and here is the result

im trying to get the players feet to be facing the surface of the planet, i added spheres to easier see the rotation of the player

so your “Direction” variable seems to be your “gravity direction”, presumably the direction the feet should face, presumably the down direction of the player (the opposite of the players y-axis). if so, then -Direction (NEGATIVE Direction, as in -1f * Direction) should be then SECOND parameter of the LookAt function. for the first parameter, i cant say what it should be, but its the direction you want the players z-axis to align to.

keep in mind that if the 2 Vector3 params you provide as arguements are not perpendicular, then the “up” will be a bit off. For your case, it seems that this would be unacceptable, so you should make sure to give provide perpendicular vectors.

Then you want:

``````Vector3 up = transform.position - CurrentPlanet.transform.position;
Vector3 projectedForward = Vector3.ProjectOnPlane(transform.forward, up);
transform.rotation = Quaternion.LookRotation(projectedForward, up);
``````

ooh thankyou this makes a bit more sense, im gonna have to work on it a bit more to understand fully as im very very new to quaternions, this is my first 3d game

this actually really helps, being able to visualize it in code