## Impulse Unit of Measurement

Official forum for the Chipmunk2D Physics Library.

### Impulse Unit of Measurement

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?
Kipt

Posts: 8
Joined: Tue Jun 07, 2016 6:48 am

### Re: Impulse Unit of Measurement

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.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/

slembcke

Posts: 4164
Joined: Tue Aug 14, 2007 7:13 pm

### Re: Impulse Unit of Measurement

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.
Kipt

Posts: 8
Joined: Tue Jun 07, 2016 6:48 am

### Re: Impulse Unit of Measurement

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.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/

slembcke

Posts: 4164
Joined: Tue Aug 14, 2007 7:13 pm

### Re: Impulse Unit of Measurement

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).
Kipt

Posts: 8
Joined: Tue Jun 07, 2016 6:48 am

### Re: Impulse Unit of Measurement

Ok, I figured it out... For some reason Box2D has a maximum speed that I'm hitting with the bullet.
Kipt

Posts: 8
Joined: Tue Jun 07, 2016 6:48 am

### Re: Impulse Unit of Measurement

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.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/

slembcke

Posts: 4164
Joined: Tue Aug 14, 2007 7:13 pm

### Re: Impulse Unit of Measurement

slembcke wrote:I'll finish an example up tomorrow probably if you are still interested.

Kipt

Posts: 8
Joined: Tue Jun 07, 2016 6:48 am

### Re: Impulse Unit of Measurement

Tomorrow never comes?
Kipt

Posts: 8
Joined: Tue Jun 07, 2016 6:48 am

### Re: Impulse Unit of Measurement

Today's tomorrow is tomorrow's today?
Kipt

Posts: 8
Joined: Tue Jun 07, 2016 6:48 am