- Home /
Position errors on rotated child objects?
I have a FPS controller player object which has camera and a gun object as it's children. The camera is controlled by a standard MouseLook script and the gun uses Quaternion.Lerp to smooth the gun's movement to follow the camera. The problem is that the different child objects of the gun object seem to move their position around slightly in relation to each otheras the gun rotates to extreme vertical look angles (looking up/down). This is really bugging me and I've messed around with my script for ages with different ways of doing it.
Here's the code for the gun's smooth follow script:
function Start() {
localRot = transform.localRotation; // save initial local rotation
curRot = transform.rotation;
}
function Update() {
// targetRot follows instantly the camera:
var targetRot = target.rotation * localRot;
// curRot follows targetRot with some smoothing delay:
curRot = Quaternion.Lerp(curRot, targetRot, speed * Time.deltaTime);
transform.rotation = curRot; // update the actual weapon rotation
}
I believe this might be to do with Quaternion-Euler conversion error but I don't think I'm doing that anywhere?
Thanks
Your answer
Follow this Question
Related Questions
Rotate an object around z axis on user input 1 Answer
How can I multiply the rotation of a mirrored object? 1 Answer
Pitch/yaw difference between 2 transforms 1 Answer
Quaternion to Matrix Conversion Error - Camera Script 0 Answers
How do you manually override mecanim's interpolation with rotations? 2 Answers