Page 1 of 1

Impulse Unit of Measurement

PostPosted: Mon Oct 24, 2016 3:30 am
by Kipt
Hello,

I just changed to Box2D due to the need of "bullets" and noticed that the impulses I was using to fire out a projectile was waaay slower. In Box2D the b2Body::ApplyLinearImpulse says the impulse is in Newton-seconds.

What is the unit of measurement for Chipmunk2D cpBodyApplyImpulseAtWorldPoint and cpBodyApplyImpulseAtLocalPoint?

Re: Impulse Unit of Measurement

PostPosted: Mon Oct 24, 2016 1:01 pm
by slembcke
Box2D uses SI units because it has a lot of hard-coded assumptions about the sizes of objects in the simulation. Ex: if your Box2D objects arent ~1 meter in size, then there can be some fairly high performance penalties. The problem is that most people don't care about true realism in a game. Look for articles on Angry Birds physics for example, all of the values they come up with are nonsense because the game is basically a cartoon that just has to "feel right" not be right.

Chipmunk was designed to avoid ever needing hard-coded assumptions like that. You can simple use whatever units you want. If you are passing seconds to the functions that expect time (like cpSpaceStep()), then your unit of time is seconds. If you are passing pixels to functions that expect distances or positions, then your unit of distance is pixels. People tend to make up numbers for mass, but again it's all relative.

Derived units are just combinations of the above. Ex: pixels/second for velocity or mass*pixels/second^2 for impulses. If you know the conversion factors for the basic units, you can find a conversion factor for the derived units.

You might also want to consider using raycasts for bullets instead of rigid bodies. They have vastly better performance, and are usually simpler to deal with in terms of collision callback events.

Re: Impulse Unit of Measurement

PostPosted: Tue Oct 25, 2016 9:17 am
by Kipt
So if you use meters as length unit, seconds as time unit and kilograms for mass unit with chipmunk is the unit of impulse then Ns? Do you know if there are any (noticeable) differences in how the velocity is calculated based on the applied impulse between Box2D and Chipmunk2D? If not I guess there is an issue in my wrapper code.

The reason I don't use ray-casting is because I need the bullet to deflect in a realistic manner from the body it hits. I also use data from the arbiter, such as total kinetic energy, so basically I would need to simulate the normal collision in the ray-hit case, not something I know how to do.

Re: Impulse Unit of Measurement

PostPosted: Tue Oct 25, 2016 10:27 am
by slembcke
If you are using those units, then it should be newton seconds then yes.

Calculating the bullet reflection and impulse/KE it would apply to an object is pretty straightforward. Maybe 5 lines of code or so and a few more for the raycasting loop. I could walk you through it if you'd like. If Box2D's continuous collision is the right tool for the job then that's fine too. Just trying to offer an alternative to rewriting a bunch of code is all. ;)

Re: Impulse Unit of Measurement

PostPosted: Wed Oct 26, 2016 2:24 pm
by Kipt
I suspect the projectile is colliding with the object spawning the body, that could explain why my Box2D integration is shooting the projectile slower.

Actually, if you'd help me out I could go with ray-casting! Since the bullets I use are very small, and circular, it would probably work without any noticeable issues. I created a new thread for that (viewtopic.php?f=1&t=7535).

Re: Impulse Unit of Measurement

PostPosted: Sat Oct 29, 2016 7:41 am
by Kipt
Ok, I figured it out... For some reason Box2D has a maximum speed that I'm hitting with the bullet.

Re: Impulse Unit of Measurement

PostPosted: Mon Oct 31, 2016 1:19 pm
by slembcke
Sorry about the delay. :-\ Had a busy weekend helping my sister with some moving. I had started on an example and got distracted with a mild bug that I found in the process. I'll finish an example up tomorrow probably if you are still interested.

Kipt wrote:For some reason Box2D has a maximum speed that I'm hitting with the bullet
Yup. ;) It has lots of hard assumptions that are easy to break. IIRC It also has limits for rotational speed that are problematic for wheels.

Re: Impulse Unit of Measurement

PostPosted: Tue Nov 01, 2016 3:51 pm
by Kipt
slembcke wrote:I'll finish an example up tomorrow probably if you are still interested.

Please do. :)

Re: Impulse Unit of Measurement

PostPosted: Fri Mar 10, 2017 6:14 pm
by Kipt
Tomorrow never comes?

Re: Impulse Unit of Measurement

PostPosted: Sat Aug 26, 2017 2:40 pm
by Kipt
Today's tomorrow is tomorrow's today?