Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I read this tutorial http://www.riemers.net/eng/Tutorials/XNA/Csharp/Series2/Camera_delay.php but i didnot unsterstand it. Is there another way to delay the camera position movement without this Quaternion and the "up position"? Basically i want the camera move slowly to another location, and i tried this:

        view = Matrix.CreateLookAt(cameraPosition, cameraTarget, Vector3.UnitY);
        cameraTarget = position;
        cameraPosition = Vector3.Lerp(new Vector3(0,8,15), world.Backward * 15,1f);

i want the camera be 15 units from an object, and move slowly until it will be behind it, but this code dosen't work.

share|improve this question
add comment

1 Answer

Assuming that world.Backward is a constant this line of code is going to return the same value every time.

cameraPosition = Vector3.Lerp(new Vector3(0,8,15), world.Backward * 15,1f);

You want to lerp between the current location and target location.

cameraPosition = Vector3.Lerp(cameraPosition, goalPosition, 0.1f);

Lerp is the interpolation function below so if value1 and value2 are the same frame after frame then returned value will never change.

cameraPosition = value1 + (value2 - value1) * amount

Also you want a value less than between 0 and 1. Ex you value of 1.0f gives you. a value of .5 will move you half way to value2 in one tick. A value of .1 will move you a tenth of the way to value2. Below is why 1.0f is a bad weight.

cameraPosition = value1 + (value2 - value1) * amount
cameraPosition = value1 + (value2 - value1) * 1
cameraPosition = value1 + value2 - value1
cameraPosition = value2
share|improve this answer
    
I know the lerp function and how it works, but I dont know exactly what to do to move the camera position to behind the object –  user1202920 Feb 17 '12 at 12:03
    
cameraPosition = Vector3.Lerp(cameraPosition, desiredPosition, 0.1f); –  ClassicThunder Feb 17 '12 at 14:28
    
I did that, and its not working –  user1202920 Feb 17 '12 at 16:12
    
@user1202920 I'm afraid you don't appear to know how Lerp works, the third parameter is how far between the two points you want the result, Vector3.Lerp(new Vector3(0,8,15), world.Backward * 15,1f); is the same as world.Backward * 15 –  Daniel Carlsson Mar 18 '12 at 17:01
    
@DanielCarlsson please be nice. –  ashes999 Dec 31 '12 at 21:02
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.