ZkillCatIV

[HELP] I need an explanation in InterpolateBetween Please

Recommended Posts

I have an understanding in the topic the only thing that I dont get is the fprogress please can explain me with detail why they use getTickCount() and add subtract and devide to get that progress I just dont get it, thank you...!!!

please not mean comments not everybody is an einstein at everything and dont say look at the wiki the wiki dont explain with details.

Share this post


Link to post

Well, I'm trying to move the camera but i dont want to use the object method and I saw that you can do it with interpolatebetween can someone tell me how please 

Share this post


Link to post

I see you already found a similar topic and that helped you, but in case you didn't understand interpolation fully, I will explain. So basically it's a function, that increments / decrements gradually between start and endpoints. So if you had 2 camera positions and you wanted to have a nice movement between the 2 positions, you would use interpolation. In theory, it returns a number between -1 and 1 over it's progression. When this curve is over, it will always return 1. Now, in MTA, you can call this function with 3 start and 3 end points and one easing type, which defines the actual curve of progression (take a look at the link in order to better understand them). Although, this "interpolateBetween" function does not remember the progression, it doesn't know whether it's finished, half way through or just started off, that is why you will have couple of variables. getTickCount() is an integer that returns the amount of time your system has been running in milliseconds, so it's unique and can be used to mark different events. For example you can save the starting time with getTickCount and in an event like onClientRender you can compare how many seconds have passed. Thing you will need:

Start time: getTickCount() whenever you call the interpolation first

Elapsed time: current getTickCount() - start time -> returns elapsed time in milliseconds

Duration: how long will it take to reach from start to the end in milliseconds -> probably it won't change 

Progress: the current state of the interpolation, to get this, use the formula: elapsedTime / duration

And you will also need 3 start and 3 end points, as I already said (although, if you need only 1 start and 1 end, just use 0's)

To wrap it up, this is how you call interpolateBetween ( remember that you will always want to run it inside render )

local start = getTickCount()
function render()
    local now = getTickCount()
    local endTime = start + 2000
    local elapsedTime = now - start
    local duration = endTime - start
    local progress = elapsedTime / duration
    local posX, posY, posZ = interpolateBetween ( startPosX, startPosY, startPosZ, endPosX, endPosY, endPosZ, progress, "Linear")
end
addEventHandler("onClientRender", root, render)

 

  • Like 2

Share this post


Link to post
On 2/14/2017 at 08:16, pa3ck said:

I see you already found a similar topic and that helped you, but in case you didn't understand interpolation fully, I will explain. So basically it's a function, that increments / decrements gradually between start and endpoints. So if you had 2 camera positions and you wanted to have a nice movement between the 2 positions, you would use interpolation. In theory, it returns a number between -1 and 1 over it's progression. When this curve is over, it will always return 1. Now, in MTA, you can call this function with 3 start and 3 end points and one easing type, which defines the actual curve of progression (take a look at the link in order to better understand them). Although, this "interpolateBetween" function does not remember the progression, it doesn't know whether it's finished, half way through or just started off, that is why you will have couple of variables. getTickCount() is an integer that returns the amount of time your system has been running in milliseconds, so it's unique and can be used to mark different events. For example you can save the starting time with getTickCount and in an event like onClientRender you can compare how many seconds have passed. Thing you will need:

Start time: getTickCount() whenever you call the interpolation first

Elapsed time: current getTickCount() - start time -> returns elapsed time in milliseconds

Duration: how long will it take to reach from start to the end in milliseconds -> probably it won't change 

Progress: the current state of the interpolation, to get this, use the formula: elapsedTime / duration

And you will also need 3 start and 3 end points, as I already said (although, if you need only 1 start and 1 end, just use 0's)

To wrap it up, this is how you call interpolateBetween ( remember that you will always want to run it inside render )


local start = getTickCount()
function render()
    local now = getTickCount()
    local endTime = start + 2000
    local elapsedTime = now - start
    local duration = endTime - start
    local progress = elapsedTime / duration
    local posX, posY, posZ = interpolateBetween ( startPosX, startPosY, startPosZ, endPosX, endPosY, endPosZ, progress, "Linear")
end
addEventHandler("onClientRender", root, render)

 

ohhhh I understand it now, its so simple but it seems hard thank you so much for your reply. finally understood that function hahhaha really you have no idea how long i have been looking for this answer.  

Share this post


Link to post

Believe it or not, when I looked at interpolateBetween myself, I felt the same, looked so complicated, I thought it's just not worth learning it. Didn't even touch it for months, then someday I decided to take a closer look and turned out it's so simple to use once you understand it. Glad I could help.

Share this post


Link to post

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.