Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'torque' divided by 'inertia' twice? #64

Closed
spacemeowx2 opened this issue Feb 17, 2015 · 8 comments
Closed

'torque' divided by 'inertia' twice? #64

spacemeowx2 opened this issue Feb 17, 2015 · 8 comments
Labels

Comments

@spacemeowx2
Copy link

See /src/body/Body.js:433

body.angularVelocity = ((body.angle - body.anglePrev) * frictionAir * correction) + (body.torque / body.inertia) * deltaTimeSquared;

and /src/body/Body.js:433

body.torque += (offset.x * force.y - offset.y * force.x) * body.inverseInertia;

(After I called applyForce, body doesn't rotate until I changed the position to {x:0,y:250000}.)

@liabru
Copy link
Owner

liabru commented Feb 17, 2015

This may depend on your particular setup.

Can you provide a jsfiddle please?

@spacemeowx2
Copy link
Author

http://jsfiddle.net/wafo2qga/1/
It's used to be C/S structs. Matter.js running on my server and send frame data to a browser. The task of the browser is to draw frames. So the code is strange.
http://203.195.196.109:8899/game.html

@liabru
Copy link
Owner

liabru commented Feb 20, 2015

It looks like you're only applying a (small) force for a single frame?
I think you need to apply a bigger force over a number of frames to get the acceleration you're looking for.

But actually, what you probably need to use is Body.setAngularVelocity which is instantaneous, where as forces are much slower acting.

@spacemeowx2
Copy link
Author

No.. You didn't get my point.
http://jsfiddle.net/wafo2qga/2/

Body.applyForce(boxA, Vector.add(boxA.position,{x:80,y:0}), {x:0,y:-0.5});

A 'small' force let the box jump so high without any rotation. Isn't it abnormal?

@liabru
Copy link
Owner

liabru commented Feb 22, 2015

I do get your point, it does seem a little strange that there's no rotation given the change in linear velocity.

So there may be an issue with angular force application. I'll investigate further, thanks.

@mattgrayisok
Copy link

I ran into this issue today too. Fix seems to be to remove * body.inverseInertia from Body.js:570.

Based on my rather limited understanding, this makes sense based on the physics because the torque isn't proportional to inertia, however the angular momentum that results from it is.

@liabru liabru added the bug label Dec 5, 2015
@jstoeffler
Copy link

Wow, I was having so much trouble getting things working, I thought it was because I didn't understand what was going on, but turned out by removing * body.inverseInertia everything makes sense now !

Is the bug still here? Or is it just me?

@liabru liabru closed this as completed in 3f9364c Dec 23, 2015
@liabru
Copy link
Owner

liabru commented Dec 23, 2015

Fixed in the latest master build, thanks guys.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants