Sign in to follow this  
TheTrope

Modify time scale in 2D physics engine

Recommended Posts

Hi,

I would like to modify time scale in a 2D physics engine. I searched about it, and matter.js seems to permit timescale modification.

In addition, i would like to set 'different timescales' for different bodies (as example: 2 object fall, one will be set to timescale:1 and the other timescale:0.5. So this last one will fall 2x slowly)

It sound nonsense, but is there a trick to do it?

I thouth about saving positions on last step, and compare them to the new one, then replacing them with a homothety value relative to the timescale. But there is a lot of cases that this can't handle

Any sugestions? :D

Thanks

Share this post


Link to post
Share on other sites

an old post but couldn't you apply an update rate to the object and use that to calculate when it should do stuff? something like

function obj(x, y, updateRate) {
    this.position = new vector2(x, y);
    this.velocity = new vector2(0, 0);
    this.acceleration = new vector2(0, 0);
    this.maxSpeed = 4;
    this.updateTime = 0;
    this.updateRate = updateRate;
    this.updateLast = 0;
}

obj.prototype.addForce = function(fx, fy) {
    this.acceleration.x = fx;
    this.acceleration.y = fy;
}

obj.prototype.update = function(step) {
    this.updateTime += step;
    if(this.updateTime - this.updateLast > this.updateRate) {
        //do your update
        this.velocity.add(this.acceleration);
        this.acceleration.zero();
        this.velocity.limit(this.maxSpeed);
        this.position.add(this.velocity);
        this.updateLaste = this.updateTime;
    }
}



but really couldn't you do this without changing "time scales" and just limit the velocity or simply apply a different force to each object

 

Share this post


Link to post
Share on other sites

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
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.