Fast bullet physics and pass-through in Chipmunk

I am making an artillery game as a learning exercise for Cocos2d-x (3.17.2) and Chipmunk physics engine; a cannon fires a shell over a random triangular mountain based on power and elevation angle.

My problem is that if I fire at high speed my shell will pass through the mountain (or inside mountain then bounce off the back-inside. Amusing but not suitable.

I get that the engine may “miss” a collision for fast moving objects.
I tried limiting the speed, but once speed is low enough that pass-through does not happen, the shell is too slow.

The mountain is made with a 3 point PhysicsBody::createEdgeChain.
The shell with a PhysicsBody::createCircle.

This seems like it would be a fairly common problem. Is there some special (more costly?) physics mode for fast moving objects? Some trick or special handling?

Since I only have one shell at a time, performance is not a huge concern for now.
I was considering using current and last point of shell sprite for each move cycle and do a linear intersection with the two lines of mountain or something, but it seems like there may be a better (already provided?) way.

Hi. There are some solutions:
1- use Ray Cast for your shells and handle visual by yourself.
2- Decrease time scale of physics engine. you can solve it 3 times every frame (Performance Hungry)
3- Change physics engine (Box2d) and use bullet objects.

1 Like

Thanks amin13a.

I hunted around in the cpp-test code, and rayCast() is just the thing I was looking for and hoping I would NOT have to implement do myself.

I tried 2, but while decreasing timescale helped I could still get occasional “shoot through”.

I may still try Box2D - not really sure what pros and cons between it and Chipmunk is yet (besides bullet objects).

I also noticed a test with a fast moving sphere which did not go through walls at edges despite moving as fast as my shell - I want to have a look at that and see what they may have done different.

I am beginning to think I should keep notes on what each test does so I know where to look for example when I have a problem :wink:

Again, thanks for giving me a hint on what to search for (rayCast).

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.