Create deceleration

Adroiid

New member
Hi everyone,

In the beat ’em up I’m creating, my character wears roller skates, so I’d like her movement to feel a bit more like she has inertia.

walkfull.gif

I’m trying to create a slight deceleration effect:

  • when the player releases a direction button,
  • after a forward jump,
  • and possibly an even stronger deceleration after a dash.

What would be the best way to handle this in OpenBOR?

Thanks a lot in advance.
 
I tried implementing a slight deceleration effect at the end of a movement or upon landing after a jump, but I encountered problems with the scripts (crashes or conflicts with the movements).

I'm not very proficient in programming yet, so I haven't been able to find a stable solution this way.

For now, I've simulated the effect using the idle animation (adding a slight forward movement in the first few frames).

Test video :
The result is satisfactory, but I lose a looping idle animation.

Do you think this approach is acceptable in OpenBOR, or is it bad practice?

Otherwise, I'll keep it because this feeling is missed in the game when it's not present.

Thanks!
 
@Adroiid,

You want to avoid animation loops for this, because that could have side effects you didn't plan for and limits your design later.

Instead, you'll want conditional script loops in the onmove event c that reduce velocity by a given % until it reaches a threshold, and then halting.

DC
 
@Adroiid,

You want to avoid animation loops for this, because that could have side effects you didn't plan for and limits your design later.

Instead, you'll want conditional script loops in the onmove event c that reduce velocity by a given % until it reaches a threshold, and then halting.

DC
@DCurrent,
Thanks, that makes sense.

I understand the idea: using an onmove script to gradually reduce velocity until it reaches a threshold, instead of faking deceleration through animation.

The problem is that I’m still very inexperienced with scripting, and I’m not sure about the exact setup for onmove / onmovex in a player model.

Would it be possible to show me a very small working example for a player character?
Just a minimal case of:

moving,
releasing left/right,
then reducing horizontal velocity by a small percentage until stop.

That would help me a lot.

Thanks again.
 
@DCurrent,
Thanks, that makes sense.

I understand the idea: using an onmove script to gradually reduce velocity until it reaches a threshold, instead of faking deceleration through animation.

The problem is that I’m still very inexperienced with scripting, and I’m not sure about the exact setup for onmove / onmovex in a player model.

Would it be possible to show me a very small working example for a player character?
Just a minimal case of:

moving,
releasing left/right,
then reducing horizontal velocity by a small percentage until stop.

That would help me a lot.

Thanks again.
@Adroiid I don't know if it will fit for your purpose, but I have an example using the updatescript event.

To apply it, just call it at the character header this way:
script data/scripts/deceleration.c

Then, create the deceleration.c file and put the code below inside it.

Code:
void main()
{
    deceleration();
}

void deceleration()
{
    void self           = getlocalvar("self");
    void anim           = getentityproperty(self, "animationID");
    float currentVel    = getentityvar(self, "currentVelocity");
    float xDir          = getentityproperty(self, "xdir");
    float rate          = 1.05;

    if( anim == openborconstant("ANI_WALK") ||
        anim == openborconstant("ANI_RUN")  ){
       
        if(currentVel != xDir){
            setentityvar(self, "currentVelocity", xDir);
        }
    }
   
    if(anim == openborconstant("ANI_IDLE")){
        if(currentVel != NULL()){
            changeentityproperty(self, "velocity", currentVel);
            setentityvar(self, "currentVelocity", xDir/rate);
        }
    }

    //DEBUG
    //drawstring(50, 60, 0, currentVel);
}

Here's the result. You can change the deceleration rate at the "rate" variable. The same goes to the animation list where it should work.


EDIT: Minor improvement in the code for better reading/editing.
 
Last edited:
@Kratus

Thank you so much for this very detailed answer.

I’ve implemented it the deceleration effect is working but the "rate" parameter doesn’t seem to affect it much on my side.

I’m now looking forward to integrating dash and dash attacks.

I also added a jump delay and a jump land animation to give more weight to the movement, so maybe that interferes with the deceleration.

Thanks again for your help!
 
Back
Top Bottom