3rd Person Camera Lerp Problem!

Hello,
I am currently making a third person camera in the UDK that switches between three different offsets based upon what the player is doing. I have one offset for rest and jogging, sprint and hardaiming. At this point, there isn't any transition between the various offsets, and I have been playing around with using a vector lerp to implement this.

The problem is this: when using a vector Lerp, the player's location on screen (ie the camera offset) changes if the player makes any hard turns with the mouse. At times, the camera can lose the player entirely. I am having trouble resolving this issue.

I have tried comparing the vector returned by the lerp function to the desired vector and then set the camera location to the desired offset, effectively snaping the view the rest of the way. This never worked out, as I found it was quite difficult to compare vectors. IT seems like this issue either stems from the fact that the camera position is dependent on the rotation of the player, but the lerp function has a constant number which is updates InterpSpeed * DeltaTime. Unfortunately, I don't know how to resolve this discrepancy, if that is actually the problem.

This is the code that calculates the offset:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
function UpdateViewTarget(out TViewTarget OutVT, float DeltaTime)

    {
        local vector CamX, CamY, CamZ;
        local MLFPawn MP;
     
        MP = MLFPawn(OutVT.Target);

        if(MP != none && !MP.bSprinting)
            GoToState('Rest');

        if(MP != none && MP.bHardAim)
         GoToState('HardAim');

        //Make sure the target is a pawn
        if(MP != none)
        {
            //Set the Camera rotation to the Player Rotation for a Fixed POV
             OutVT.POV.Rotation = PCOwner.Rotation;

             /*Pass in the Camera Rotation to get 3 vectors to help calculate                  the desired offset*/
            GetAxes(OutVT.POV.Rotation, CamX, CamY, CamZ);
        
            //Grab the current camera location
            CurrCamLoc = OutVT.POV.Location;
           
            //Calculated the desired camera location from the targets location
            DesiredCamLoc = OutVT.Target.Location - CamX*SprintOffset.X
                + SprintOffset.Y * CamY
                + SprintOffset.Z * CamZ;

 /*This is the problem location, this function returns a vector that is a certain amount closer to the DesiredCamLoc, but it also causes the camera's position to change dramatically if the player is rotating fast*/
       OutVT.POV.Location = VInterpTo(CurrCamLoc, DesiredCamLoc, DeltaTime, 15);      
          

            //Make sure we can see the player mesh 
            MP.RemoveMeshVisibility(false);

        //Check the camera collision, make sure we don't get stuck in the model
         CheckCameraCollision(MP, OutVT, CurrCamLoc);

        }
        else
        { 
/*If for whatever reason the view target is not my pawn class, call the function up the chain to calculate the viewtarget*/

            super.UpdateViewTarget(OutVT, DeltaTime);
        }
    }
Last edited on
Sounds like an interesting problem.

Why did your strategy of snapping to the final position not work?

A camera can have three vectors:
position - where it is
look_at - what direction its pointing in
up - perpendicular to look_at, indicates the direction of the top of the screen

Don't see why the snapping strategy shouldn't work provided you take account of all factors in positioning the camera
Topic archived. No new replies allowed.