# Make an object point to another while keeping is forward

Hi there,

I have some handy execute in edit mode scripts I wrote in order to make level design easier. One of the big things I wanted is to be able to point an object’s bottom to be at the same orientation as the floor beneath it - in other words, its transform.up should be pointing in the same direction as the normal at the point below it.

So if I put a chair on ground that was slanted 15º, then the chair would also be slanted 15º. Make sense?

I have this implemented by doing a raycast downwards, if it hits anything, moving the object there and setting transform.up = raycastHit.normal (also have tried raycastHit.collider.transform.up). This works for aligning the object, but unfortunately also rotates the object around (its forward rotation is changed too).

Is there some proper way to do this?

This would be totally doable if there were a way to get/set the rotation around a local axis. In this case, I only want the rotation around the Y axis to matter, but as far as I see there are no functions to basically do:

``````float oldYRot = transform.GetRotationAroundAxis( transform.up );
transform.up = target.transform.up;
transform.SetRotationAroundAxis( oldYRot, transform.up );
``````

Hello there!

Interestingly enough I also recently encountered a situation where this was necessary. This is my solution:

``````public static void AlignToPlane(Transform trans, Vector3 planeNormal)
{
Vector3 projection = ProjectOnPlane(trans.forward, planeNormal).normalized;
trans.rotation = Quaternion.LookRotation(projection.normalized, planeNormal);
}

public static Vector3 ProjectOnPlane(Vector3 vector, Vector3 planeNormal)
{
return vector - Vector3.Dot(vector, planeNormal) * planeNormal;
}
``````

Basicly you project the forward vector onto the plane, then create a look-rotation with the plane’s normal as up and the projected vector as forward.