Collision with physics question

Hi guys,

I have a little problem. I am using a runtime collision listerner to detect collision amoung many objects. In general it works great BUT for one type of collision it is not complete ok. The one I have issue is a collision between a cross-hair (movable with a joystick) and asteroids flying around the screen. The goal is too move the cross hair above the asteroids and press a fire button to destroy them (my upcoming game SpaceCommand) in the most part to works but only if I move the cross hair (physics object) and collide with the asteroid (while in the same time press the fire button) If on the other hand, but many time the collision do not happen even if the cross hair and the asteroid are one on top of the other. They collide (and the asteroid gets destroy) if I move cross hair around the asteroid a little. If I simply put the cross hair on top of the asteroid and simply fire, nothing happen.

I am wondering if using the oN collision event is the correct in this situation. Not sure if post collision will be better but I can of doubt it. If I cannot figure this out (with your help!) I may have to go the route of collision without physics for that type of collision (both objects moving around) I will keep the physics collision between asteroids and planets (planets are fixed object on the screen) because it works great in that instance.

Any pointers? Advice?

Thanks guys.

Mo

[import]uid: 100814 topic_id: 28448 reply_id: 328448[/import]

One more thing. I want to avoid collision without physics mostly because I do not want to check every distance between asteroids and the cross hair. I could limit to only asteroids on the screen but that would also mean also checking that the asteroid is inside the screen area…

By the way if I have no choice but to use collision without physics, what would be the best way to avoid the slow down of accessing the asteroids X and Y locations since I believe they are “slow” to access. My game is a fast game. I will assume using a local temp variable but my asteroids objects are inside a table…

Thanks again.

Mo [import]uid: 100814 topic_id: 28448 reply_id: 114829[/import]

Hi Mo,

Sometimes 2 bodies won’t interact properly if they are merely “placed” in collision with each other. I don’t know the best way to explain why this happens, but it does, and seems to be standard behavior.

Fortunately, the solution that usually works is to just “flash” one of the bodies (in your case, the crosshair) when you place it via some condition where it will go directly on top of an asteroid versus moving into collision state with the asteroid. Do this simply by making the body inactive then active in an immediate sequence:

crosshair.isBodyActive = false ; crosshair.isBodyActive = true

You won’t notice this happening, but hopefully it solves the problem you’re having. By toggling the body on and off, you will get a phase return on BOTH actions… “ended” when you turn it off, “began” when you turn it back on.

Let me know if this helps. If not, the issue is likely something else.

Brent Sorrentino
[import]uid: 9747 topic_id: 28448 reply_id: 114897[/import]

@Brent: WOW! Thanks! I will try and report here. I was not sure there a a solution I recoded as a collision without physics (just for the cross-hair and asteroids) but I would prefer your solution if it would work.

Thanks again.

Mo. [import]uid: 100814 topic_id: 28448 reply_id: 115282[/import]