# Move camera

## Recommended Posts

What is the best way to move the camera from one point to another? (I am talking about math)

Of course I have to put it on client Render.

```

setCameraMatrix (117.5101852417, 163.30557250977, 5579.2065429688, 116.48139190674, 156.49519348145, 5579.0087890625)

local posX, posY,posZ = 120.94383239746,162.29713439941,5579.5678710938-- location2
function ()
local xU, yU, zU, xUt, yUt, zUt = getCameraMatrix()
setCameraMatrix (xU, yU, zU, 116.48139190674, 156.49519348145, 5579.0087890625)
end)
```

You can use interpolateBetween function that is very useful for your problem.

http://wiki.multitheftauto.com/wiki/InterpolateBetween

```setCameraMatrix (117.5101852417, 163.30557250977, 5579.2065429688, 116.48139190674, 156.49519348145, 5579.0087890625)

local progress = 0.0; -- value between 0 and 1 will be used to get the new position of camera (0.5 will be half way through between the 2 points)
function ()
if progress < 1 then
progress = progress + 0.002; -- increase to move the camera faster
end
local x, y, z = interpolateBetween( 117.5101852417, 163.30557250977, 5579.2065429688, 120.94383239746,162.29713439941,5579.5678710938, progress, "Linear" );
setCameraMatrix (x, y, z, 116.48139190674, 156.49519348145, 5579.0087890625)
end)
```

woow thanks

```local distance = BeginX - endX
local distance_per_frame = distance /framecount
x = BeginX + distance_per_frame
```

But interpolateBetween is much better :3

No problem.

This is useful not only for 3D animations but also for 2D. You can move windows using the same function as well as resize them. For example a window popping up from outside of the screen or resize and pop up (eg. like in Windows 7). You can use different easing types for different animation styles.

Good luck.

btw:

What is the best and lagg free way to check when the camera reached it's point?

Once the "progress" will be >1 then the camera reached the destination so just add "else" to the "if" statement and then stop the camera movement (removeEventHandler + setCameraTarget to bring it back to player). You can also add new event and use trigger(Server)Event so that other scripts can use that event for their own purposes. I like using custom events.

aha,

It works very well, I made what I wanted to make.

I send you my script maybe it inspires you. (just the cam)

• 3 years later...

Thank you so much this post helped me 100%

P.S 50p you are awesome dude

Edited by ZkillCatIV

## Create an account

Register a new account