Jump to content

Move camera


IIYAMA

Recommended Posts

  • Moderators

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  
addEventHandler("onClientRender",root, 
function () 
    local xU, yU, zU, xUt, yUt, zUt = getCameraMatrix()  
    setCameraMatrix (xU, yU, zU, 116.48139190674, 156.49519348145, 5579.0087890625) 
end) 

Link to comment

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

https://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) 
addEventHandler("onClientRender",root, 
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) 

Link to comment
  • Moderators

woow thanks

I was thinking about:

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

But interpolateBetween is much better :3

Link to comment

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.

Link to comment

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.

Link to comment
  • 3 years later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...