How can i do Easein and Easeout behavior

0 favourites
  • 7 posts
  • I want to put easein & easeout on a object but I don't want to use any behavior plugin like LiteTween

    I just want to do the same with formula in event system.

    the reason is

    when mouse button is on hold object should come upside

    but if i release the button, object should go down weather it reached destination point or not

  • dropbox.com/s/te2ikrwrib81oi7/easethings.capx

    Fantastic

    But seems very difficult to understand

    but i am trying to get it

    let see how much i can understand from it

    Can you describe the formula how it works

    and what is dtt and how its works ?

  • Allow me to start with some very important basics: the difference between Speed and Steps.

    Speed = Distance / Second. Assume that Distance is the same. One second just is the same on any device everywhere in the world. Hence, Speed is the same on any device.

    Its units = Pixels / Second.

    You will find Speed as property in the behaviors. Speed for Bullet, by instance is in Pixels / Second. Hence a bullet moves at the same speed on any device.

    Steps = Distance / Tick. No tick is the same length on every device. Depends on the FPS the game is running in. So you cant call this 'speed'.

    The relation between Speed and Steps is simple. It is just :

    Steps = Speed * dt.

    So if you bring the same sprite in a layout. One with a bullet behavior with a speed property of 400. And the other you move with 'move forward' in steps 400 * dt. You will see that they move at the same speed.

    In my example, the speed is written as an instance variable on Sprite 'thing'. It is in Pixel / Second units.

    Since i gonna use 'lerp' i need Steps. Meaning an amount of pixels to move every tick so that the resulting speed = thing.speed.

    In my example i only move over X to simplify the example. It is basically the same for Y.

    Also, lerp is in the form of lerp(A,B,%). In the example A and B are static. It is a whole other story when A and/or B are dynamic, like a camera chasing a player. % stand for a number between 0 and 1 (2 will overshoot the destination by B-A). 0 = start position. 0.5 = half way. 1 = end position.

    Since A and B are static, i know the distance that will be moved. And since i nailed the speed .. The time it will take to move that distance = distance / speed.

    If i read your post, that is what you gonna need.

    So i know the time, now i can just start a timer. When you start a timer ("tag"), its Expression Object.Timer.CurrentTime("tag") gives me the elapsed time in seconds.thousands.

    This timer ticks the same seconds away on any device (when its FPS stays above the minimum allowed).

    But now the lerp(A,B,%) needs a % between 0 and 1. So if we start a timer for 5 seconds, we need to normalize this to a range (0 - 1). Now 5 / 5 = 1. Simple as that. So normalized CurrentTime = Object.Timer.CurrentTime("tag") / the time it will take in the end.

    That is what i stored in the local variable t.

    So t = Sprite.Timer.CurrentTime("tag") / Sprite.ExpectedTime and returns a number between 0 an 1

    So the lerp is now as simple as lerp(Sprite.StartX, Sprite.StartX + distance, t) for a linear movement.

    Since t is calculated coming from a timer that runs the same on any device, t is truly ALWAYS non frame independent.

    t = pixels / tick. It is Steps derived from Speed.

    t is not the same number on any device, simple because the lerp is executed more times / second on a fast device compared to a slow device.

    So, now we have linear covered.

    The others are just the same. They just change t (the steps) with a non linear mathematical formula.

    They change t in a way that zero is still zero and 1 is still 1 in the range (0 - 1)

    That is the value dtt. I like 'dt' more as name for that value, but that is taken by the system.

    So if you look at the quad ...

    dtt = t<0.5 ? 2*t*t : -1+(4-2*t)*t

    When t = lower then 0.5 (it goes in a range from 0 to 1), so when it is not halfway yet ... this returns ...

    2*t*t (halfway this = 2 * 0.5 * 0.5 .. or still 0.5)

    More then half it returns

    -1+(4-2*t)*t

    Those formulas you just find on the internet. I did. Figuring them out is to much math for me. But i can copy past / adapt.

    Hope that helps.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Bravo 99Instances2Go really Nice tutorial and really interesting Topic, I was interested in learning more about this topic for a long time, and now I have more clear Idea, thank you for sharing with us your knowledge

  • Additional. What is so darn nice at the MoveTo plugin by rexrainbow ? (kinda same for LiteTween). Why i prefer them.

    For me that are

    (1) the conditions. Like 'Is moving'.

    Do i know if it is moving ? Yes i do, as long as Sprite.Timer.CurrentTime("tag") = not Zero, it is moving.

    (2) It stops automatically stops when target is reached.

    Is also happening in example.

    (3) It has a trigger 'On hit target'.

    I can use the 'On timer' as a trigger for that.

    (4) It is personal, truly instance aware. Each instance can have different targets and speeds.

    Mimicked in my example. If you pick them by comparison, based on Sprite.Timer.CurrentTime("tag") = not Zero, it picks only those that are moving.

    (5) When done, it is not executing lines. Good for performance.

    In my example, when the timer is not running, none of the actions run.

  • great explanation

    i have learn a lot from this.

    Now the only need is

    PRACTICE

    PRACTICE

    AND

    PRACTICE

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)