liabru / matter-js

a 2D rigid body physics engine for the web ▲● ■
MIT License
16.65k stars 1.96k forks source link

Acceleration units #1157

Open sverdin1 opened 1 year ago

sverdin1 commented 1 year ago

Using p5.js library to display a dotted arc for the trajectory of an object.

I've putting random numbers in for accelerationDueToGravity, so I think I'm on the right track - but what value should accelerationDueToGravity be for the object to follow the arc perfectly?

vectorX = mouseX - initialX; vectorY = mouseY - initialY;

accelerationDueToGravity = ; timeStep = 0;

for(let i = 0; i < 1000; i++){ timeStep += 0.1;

    // s1 = s0 + ut + 0.5*a*t^2
    pointX = initialX + vectorX*timeStep; // a = 0
    pointY = initialY + vectorY*timeStep + 0.5*accelerationDueToGravity*(timeStep**2);

    point(pointX,pointY);

}

Thanks.

ggorlen commented 1 year ago

It's unclear to me how this relates to matter.js.

sverdin1 commented 1 year ago

Sorry, I can see how this is unclear.

I have created a body using matter.js - positioned at (initialX, initialY) - and I am trying to map its trajectory through the 1000 points of the for loop. I have not been able to do this without a value for acclerationDueToGravity.

What value should I plug in please?