How to detect collision between "static" and "kinematic" objects?

I have a gun shooting bullets in my game and want to detect once a bullet hits a static object like a platform or a wall (to remove the bullet).

The walls are static objects while the bullets are "kinematic". Since I don't want the bullets to be affected by gravity, I think there is no other choice as to set them to "kinematic". The bullets should fly straight into one direction (no gravity etc.)

Evank wrote that "The general rule in Box2D is that a collision event requires at least one of the bodies involved to be dynamic. Static and kinematic bodies don't collide with each other in any combination."

Indeed I can't get the collisions to work. So how could this be solved then..?

Anyone?

How could I detect collisions between bullets (without gravity) and level objects?

Actually, this problem could be reduced to "how can I use physics collision detection without the need to include gravity".

Hi,

I had a similar problem so hopefully this helps you out.
Basically what I did was set the ball(in your case bullet)
to dynamic but set Gravity to 0, 0 and works fine!

Check Out this link:
https://developer.anscamobile.com/forum/2011/02/07/object-goes-through-objects-and-walls

I am glad that I got a reply at least (thx!)

Well, this is what I came up with, too -but what if you need to use gravity in your game? Isn't there another solution to detect collisions between static and kinematic objects?

I've never tried it, but an idea that comes to mind is applying a force equal but opposite to the gravitational force to your bullet. The net effect should be that there is no gravity on that object then.

No, this unfortunately doesn't work. This will make the object "float" down a little bit first, then it changes direction and lifts slowly upwards like a balloon.

I am also having this problem. I stared at my code for hours before realizing maybe static and kinematic bodies don't collide.

Is there anyway around this besides the aforementioned ideas?

Nick

How about attaching a dynamic sensor to the kinematic bullet?
Another option is to do it without physics.
Not sure if collision events fire without a physics body, but you CAN do distance check (pythagorean theorem stuff) and AABB check (Axis-aligned bounding box) to see if another object's bounds fall within overlap of the bullet (and do that every frame) But since physics bodies have iterated collision checks between frames, they're more reliable for collisions than almost any other method I mentioned in the case of very fast moving, small objects like bullets (be sure to set isBullet=true), so although to me it seems rather overkill, you can try attaching a dynamic sensor to the kinematic bullet so the bullet determines the sensor's position.

In a much older thread related to the odd effects static objects have on dynamic objects (I've lost the link) I think evank pointed out that it was because static objects are effectively "an immovable object" which screws up the physics engine's math.

I believe the solution to that problem is the same for yours: create a small static object somewhere off screen. Convert any previously static object to dynamic and weld them to the new, hidden static object with a weld joint.

This will cause the objects which need to remain still to do just that but also interact with other sensible objects in mathematically sensible ways, ie: you kinematic objects etc.

views:2160 update:2012/2/8 8:46:10
corona forums © 2003-2011