🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

physics engine stacking is not stable

Started by
2 comments, last by bzt 4 years, 6 months ago

I am writing a simple 2d physics engine with javascript, but something worng here.

I put 4 boxes vertically, but they always tilt slightly(slight rotation) to a side even though box 9 is on the flat ground. And after few seconds they fall on the ground because of the tilt. I have no idea how to fix it.

A student 

Advertisement

Hi, I'm interested in the problem , what kind of algorithm do you use to handle the resting contact of the blocks ?

The solution is clearly to figure out the reason for the tilt. Could be a simple rounding problem, which is easy to solve by adding a half-pixel coordinate (something like box_coordinate = Math.round(floatvar + 0.5) + "px"). Use your browser's javascript console and debugger. Put a lot of console.log calls in your code to locate where the incorrect value is calculated (or learn how to use breakpoints and step-through and follow the code that calculates the box's position and rotation). As I've said, looks like a simple rounding error to me, you just have to find out where it happens.

Cheers,
bzt

This topic is closed to new replies.

Advertisement