# Tag Info

3

It seems like you accumulate transformations. What you need to do instead is to keep rotation as euler angles pitch and yaw and then calculate final rotation from them.

2

You can create a quaternion from an axis and the angle. Use this to create a quaternion to represent the rotation around the normal of the plane by the angle theta. Then compose that quaternion with your quaternion q, which will yield a new quaternion q' which is equivalent to rotating q round the normal of the plane by the angle theta. You need to be aware ...

1

Your answer leaves out the step of actually applying the direction-to-aim to the parent. Depending on how you use directionToAim, the parent (ship) might roll (stop being upright). A slightly simpler solution, which is immune to roll in most cases: //Get the rotation we would apply to the child to make it look at the target Quaternion rotation = Quaternion....

1

One idea is that you transform to a coordinate system where up is actually Vector3.up then do whatever clamping you need via standard Euler angles, and then transform it back. So I think something like this (this is the version in Unity C#, but take it as pseudocode) would work: public Quaternion GeneralEulerClamp(Vector3 targetNormal, Quaternion ...

1

Check this link. In your case, it would be, I think: Vector3 targetPosition = kbcrd.playerToEngage.thirdPersonPlayerModel.shootTarget.position; targetPosition .y = 0; Vector3 botPosition = pb.thirdPersonPlayerModel.gunDirection.position; botPosition.y = 0; Vector3 targetDirection = targetPosition - botPosition; float singleStep = speed * Time.deltaTime; ...

Only top voted, non community-wiki answers of a minimum length are eligible