Jump to content

Modify time scale in 2D physics engine


TheTrope
 Share

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

Link to comment
Share on other sites

  • 1 month later...

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

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...