Good behaviour for ease movement?

0 favourites
From the Asset Store
Setup and ready for your art, animations and story. Viral Storybook App Template.
  • Currently I'm using lerp a lot for smoothing movement (to simulate easeIn/Out. Using a lot of them I'm wondering if there's any good behaviour that does the same thing? I'm guessing that using behaviours are a bit more performance friendly as well.

    Any such behaviours available? I tried LiteTween but not doing exactly what i wanted as you has to specify a duration of the tween. I'm more looking for something to constantly smooth things like viewport scrolling, objects that follow the mouse pointers etc.

    Any suggestions?

    Thanks

  • Cosine interpolation cosp(a, b, x) maybe

    Theres also:

    qarp(a, b, c, x)

    cubic(a, b, c, d, x)

    They are aggressively more complicated however.

    Rex has several behaviors that are simpler to implement, moveto, spline, etc.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Cosine interpolation cosp(a, b, x) maybe

    Theres also:

    qarp(a, b, c, x)

    cubic(a, b, c, d, x)

    They are aggressively more complicated however.

    Rex has several behaviors that are simpler to implement, moveto, spline, etc.

    I've tried both qarp and cubic, but not getting the desired effect.

    When mouse left is down, i want the object to accelerate smoothly from 0 to a certain speed based on the distance to the mouse, then when mouse is up I want it to decelerate to zero speed.

    using lerp(self.x,mouse.x,0.1) has the desired effect for slowing the object down as it is getting closer to Mouse.X. But the start of the movement is sudden (max speed from start), getting slower and slower as it approach Mouse.X. I don't know how I can smooth out the start of the movement.

    I'm basically looking for a curve like this. I know how to do it based on time (but that's not what I'm after), but I don't know how to do it based on distance.

    The max speed of the object should be somewhere in the middle.

    When i click. I want object to accellerate to a "Max speed" determined by the object current distance to mouse. Max speed should automatically get slower as the object approaches destination (Mouse)

    I'm just guessing here.

    lerp(a, b, x*m)

    X has to be the max speed. (m) The modifier has to be a value, that is pretty close to zero, when the object starts to move and closer to 1 when it's approaching max speed.

    a = current position, (not starting position as the mouse can move around)

    b = target position, (the current position of the mouse)

    x = maximum speed. (the maximum speed)

    m = modifier (a value that smoothly scales from 0-1 based on distance where further is closer to 0 and closer is closer to 1)

    maybe I'm doing it all wrong, and some math genius here can help me out?

    lerp(self.X,mouse.X,0.1) has the desired effect except that the start of movement is snappy not accelerating.

    I want the object to smoothly catch up to the mouse current position.

  • Basically a way to apply torque when the distance between mouse and object is far.

  • One way is to keep track of the velocity. Basically it starts at 0 and accelerates (ease in). Then you can calculate the distance it would take to decelerate to zero and use that the change the acceleration to decceleration (ease out).

    Here's a link of the idea:

  • One way is to keep track of the velocity. Basically it starts at 0 and accelerates (ease in). Then you can calculate the distance it would take to decelerate to zero and use that the change the acceleration to decceleration (ease out).

    Here's a link of the idea:

    Thank's rojo. I'll test that out....

    Happen to know if there any plugin/behaviour that does the same thing? LiteTween is based on time, not distance, so that wasn't very useful in this case.

  • R0J0hound

    I tried your code example It's nearly there but had some quirks. Object really never reaches Mouse, and starts orbiting the mouse pointer, or sometimes it shoots away randomly, after getting close. How would go about to stop the object to overshoot target, and start orbiting? I just need it to home in, then stay there.

    https://dl.dropboxusercontent.com/u/20560446/Scirra/smoothchase.capx

  • I found this javascript code, for a 2D chase camera... Maybe i can convert it to C2 events somehow.

    float lerp = 0.1f;

    Vector3 position = this.getCamera().position;

    position.x += (Obj.x - position.x) * lerp * deltaTime;

    position.y += (Obj.y - position.y) * lerp * deltaTime;

  • Lerp the acceleration perhaps.

    Mouse is down

    ->object has line of sight to mouse.x,mouse.y, set position to lerp(self.x,mouse.x,lerp(speed,minspeed,acceleration*dt)*dt) lerp(self.y,mouse.y,lerp(speed,minspeed,acceleration*dt)*dt)

    ->else set position to lerp(self.x,mouse.x,lerp(speed,maxspeed,acceleration*dt)*dt) lerp(self.y,mouse.y,lerp(speed,maxspeed,acceleration*dt)*dt)

    That is with the line of sight behavior on the object, and an else to the los event.

    Of course that wouldn't cover when the mouse was up.

    Might need a boolean to signal that if you want it to continue to where the mouse was.

  • newt

    Say, we use that to make a sprite hunt the mouse.

    Lets start the sprite far away from the mouse, and lets not move the mouse.

    The sprite will now 'catch' up with the LineOfSight kicking in at one point.

    If we now move the mouse, the LineOfSight is still kicking in, while you really want the speed (starting speed) defined in the else. (if i understand you right). So we start at maxspeed.

    Also ...

    When the lerp is written as lerp(positionSprite,positionMouse,lerpfactor) ....

    positionSprite & positionMouse are dynamic. So the lerpfactor is altering the next position allready when it is static.

    Make also the lerpfactor dynamic and i suspect that there will be weird feedback (but i did not try it)

  • 99Instances2Go

    yeah the problem is mostly visible when using touch using on mouse down condition. if object is at standstill, and i click somewhere else regular lerp(sprite.x,mouse.x,0.1) will start fast & decelerate towards that point, where i want the sprite to first accelerate.

    I need some kind of modifier for inertia or torque that increases from 0 to 1 dynamically in some way, to simulate the acceleration.

    Maybe if i can get the XY position of a middle point between sprite and target and use that instead of the mouse,

  • tunepunk

    That js code you posted is the same as lerp.

    We should be able to eliminate the orbit by just having a speed toward the target instead of seperate xy velocities.

    Var speed=0

    Distance(sprite.x,Sprite.y,mouse.x,mouse.y) > (speed^2)/(2*100)

    --- add 100*dt to speed

    Else

    --- subtract 100*dt from speed

    Every tick

    --- Sprite: move speed*dt pixels at angle angle(self.x,self.y,mouse.x,mouse.y)

    That should be closer. A bit more work could be done on the slowing down bit. Like instead instead of just using 100 as the decceleration we could calculate the required deceleration based on the remaining distance and speed.

  • Here's my result:

    https://dl.dropboxusercontent.com/u/542 ... mouse.capx

    But a steering behavior would look nicer:

    https://gamedevelopment.tutsplus.com/tu ... amedev-849

    https://gamedevelopment.tutsplus.com/tu ... medev-1303

    Here's my experiment with that:

    https://dl.dropboxusercontent.com/u/542 ... rival.capx

    The easing curve isn't symmetrical though.

  • Ty 4 the experiments.

  • R0J0hound Those are some really neat examples. I've learnt a lot. The steering example feels super smooth.

    I'm still not there yet as I have to optimize it for touch input. A tap on screen still needs an acceleration as well. The deceleration is not the big issue, it's more the acceleration. As you can see here on this screengrab from you steering curve tapping screen or rapidly moving target to a new position.

    This is how it behaves on rapidly changing target, which is what i need to smooth. So combining all of your awesome earlier examples there might be a solution.

    I tried a similar approach using bullet behaviour and a condition from one of your earlier examples. Bullet behaviour has a built in acceleration which i'm trying to replicate in events.

    Your first link for this solution was the closest so far, but it was behaving a bit weird, and overshot target and started to orbit. I need to dampen the deceleration somehow

    viewtopic.php?f=147&t=163491&p=989820&hilit=Stopping+distance#p989820

    here's a link to a capx with that approach.

    https://dl.dropboxusercontent.com/u/20560446/Scirra/smoothchase.capxv

    Thanks a lot for your help, I feel I'm nearly there.

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