x


Ideas on making a Lerp(Camera1, Camera2) ?

I am looking for some ideas on making a lerp function between 2 cameras on different parts of the scene graph. This feature is in regards to a shouldered gun. Meaning, I child a camera to a gun, and when I shoulder the weapon, the gun is moved such that it has the same orientation as seen from the gun camera's perspective.

I almost have this working: I have translation working but I am missing a key math step when with rotations.

So to give some more concrete details, my scene graph is as follows:

RootScene    
   -> Player
     -> MainCamera
       -> Weapon
         -> ShoulderedCam

Recap: I want 'weapon/gunobject' to be moved in a way such that when you are looking through MainCamera, it looks the same as if looking through ShoudleredCam.

//And I have my script as follows:
GameObject GunObject = ...;
Camera playerCam = ...;
Camera gunCam = (Camera)GunObject.transform.FindChild("ShoulderedCam").GetComponent(typeof(Camera));

Vector3 StartShoulderPos = gunCam.transform.parent.localPosition;

Vector3 worldDif = (playerCam.transform.position - gunCam.transform.position);
EndShoulderPos = StartShoulderPos + gunCam.transform.parent.InverseTransformDirection(worldDif);


    // Troubles ?        
StartShoulderRot = playerCam.transform.localRotation;
EndShoulderRot = StartShoulderRot*Quaternion.Inverse(gunCam.transform.localRotation);

And in the tick I just lerp betwen start -> end, and slerp between rotStar and rotEnd...

I would appreciate any pointers on which transform I am missing here :)

more ▼

asked Nov 10 '10 at 09:24 PM

Jeston 1 gravatar image

Jeston 1
129 8 9 16

(comments are locked)
10|3000 characters needed characters left

0 answers: sort oldest
Be the first one to answer this question
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x2987
x1274
x261

asked: Nov 10 '10 at 09:24 PM

Seen: 861 times

Last Updated: Nov 10 '10 at 09:31 PM