TheTrope Posted May 10, 2017 Share Posted May 10, 2017 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? Thanks Quote Link to comment Share on other sites More sharing options...
away168 Posted May 15, 2017 Share Posted May 15, 2017 I may not be able to answer your question, but maybe this link may help you to find your answer: http://gafferongames.com/game-physics/fix-your-timestep/ Quote Link to comment Share on other sites More sharing options...
hotfeet Posted July 13, 2017 Share Posted July 13, 2017 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.