Transform.Rotate in local space on one axis

I have a map that is locked to the gyroscope so world space coordinates are all over the place.

I’m trying to track and and follow an object using local space.

I also want to have a rotation speed, so I’m trying to use Quaternion.Slerp, but I just read that Quaternion is for world space only - probably the source of my problem.

    theDirection = (VBall.position - transform.position).normalized;
    theRotation = Quaternion.LookRotation(transform.position - VBall.position, theDirection);
    theRotation.y = 0f;
    transform.rotation = Quaternion.Slerp(transform.rotation, theRotation, Time.deltaTime * RotationSpeed);

I’ve tried many thing including transform.localPosition but nothing seems to work the way I want it to. This script will rotate around to the object, but it slerps from a coordinate that is world space, so it rocks on the Y axis as it makes the transistion to the new coordinates.

Question; Is there a way to Lerp or Slerp from on rotation to another rotation using only local coordinates?

Most people won’t have this issue since the map is tied to a static world space coordinate.

Though I’m not 100% sure I fully understand, I’ll take a shot at your problem:

var pos = ProjectPointOnPlane(transform.up, transform.position, VBall.position);
theRotation = Quaternion.LookRotation(pos, transform.up);
transform.rotation = Quaternion.Slerp(transform.rotation, theRotation, Time.deltaTime * RotationSpeed);

function ProjectPointOnPlane(planeNormal : Vector3 , planePoint : Vector3 , point : Vector3 ) : Vector3 {
	planeNormal.Normalize();
	var distance = -Vector3.Dot(planeNormal.normalized, (point - planePoint));
	return point + planeNormal * distance;
}

Note that your use of Slerp() here will produce an eased rotation. If you don’t want eased, use Quaternion.RotateTowards() and adjust ‘RotationSpeed’ up.

This code works by constructing a mathematical plane on the local up running through this object and projecting the ball position on that plane. This new position, combined with specifying ‘transform.up’ in the LookRotation() will result in a rotation only on the local ‘y’ axis. I’m not sure what would happen if the ball were directly above or below this object, since this code would result in a Vector3.zero for the direction passed to LookRotation(). If it is possible in your game, you might have to test for the situation. That is only do the rotation if (pos - transform.position != Vector3.zero).