Collision problem : Static, dynamic or kinematic ?? Static-Kinematic collision

Ok here is my scenario:

I want my player object in the game not to be affected by gravity. And an obstacle in the way of the player must not be affected by gravity as well.

Now how do I detect collisions between the player object and the obstacle. The player object cannot be kinematic because I do not think Corona allows you to detect collisions between a kinematic and a static object. And Collisions between static objects is not possible as well.

[import]uid: 64174 topic_id: 12326 reply_id: 312326[/import]

You can use a kinematic body because kinematic bodies are affected by forces but not by gravity, you can read about physics bodies here. Now for the detection, it sounds like you are going to have to use a collision detection function, you can read about it and find samples here.
If you need any more help, let me know.

-Chris [import]uid: 17138 topic_id: 12326 reply_id: 44902[/import]

Hi Chris,

I Do not think you understood my question. To not being affected by gravity, my objects must be either static or kinematic.

Since I need both player object and obstacle to be non-gravity-affectable, Both must be either static or dynamic.

Now Corona doesnt detect collisions between 2 static objects or collision between a static and kinematic object
[import]uid: 64174 topic_id: 12326 reply_id: 44905[/import]

Oh I understand now, i’m not completely sure, but i don’t think that is possible, like you said you can only detect static and dynamic or dynamic and kinematic collisions. What are you trying to do with this? Maybe there is another way of approaching it, with the same result in your app. [import]uid: 17138 topic_id: 12326 reply_id: 44910[/import]

I think you can set object.isSensor=true and detect the collisions.

I think…

Good luck

Larry

DoubleSlashDesign.com [import]uid: 11860 topic_id: 12326 reply_id: 54740[/import]

Yup.

Setting an object to dynamic and setting it as a sensor body sounds like the way to go. [import]uid: 84637 topic_id: 12326 reply_id: 54754[/import]

Setting a dynamic body as sensor body doesn’t make it non-affect-able by gravity right? The sensor body still responds to gravitational force.

Still,never mind. I found a work around solution.
Thanks for your replies. :slight_smile:

[import]uid: 64174 topic_id: 12326 reply_id: 54759[/import]

you could still set your bodies to kinematic and static but also set the isSensor = true that way you can detect when a collision occurs.

But if you found a work around what did you do ?

Thanks

Larry [import]uid: 11860 topic_id: 12326 reply_id: 54800[/import]

@Larry

I needed both my character AND the obstacle to be non-gravity-affectable. So both cannot be dynamic, and hence collisions can’t be detected(as corona requires at least one object to be dynamic for detecting collisions).

Solution? I needed this above mentioned scenario only for certain durations. So I changed the bodyType of the objects dynamically using some other sensors.

:slight_smile:

[import]uid: 64174 topic_id: 12326 reply_id: 54803[/import]

No it doesn’t work, kinematic and static object do not collide, regardless the value of isSensor property. [import]uid: 94012 topic_id: 12326 reply_id: 58712[/import]

A work around I came up with is to add two bodies, one kinematic and the other one dynamic, having the same shape, and stick them together with a weld joint. That way the kinematic object works like before, and collisions will be detected by the dynamic object attached to it. You can make the dynamic body isVisible = false, collisions will still be detected.

Another way to solve this would be Runtime:addEventListener(“enterFrame”, onEnterFrame) and detecting when the objects intersect each other, but maybe this is more memory consuming…

Any other solution ? [import]uid: 94012 topic_id: 12326 reply_id: 58713[/import]

@Andre Aah! the first solution is foolproof! the idea of joints never occurred to me! :slight_smile: [import]uid: 64174 topic_id: 12326 reply_id: 58727[/import]

Thanks andreimarincas87, welding a dynamic body to a kinematic body did the trick. Nice solution. [import]uid: 58388 topic_id: 12326 reply_id: 62333[/import]

This post answers some questions I had about kinematics and collision.

But tell me if I’m wrong : collision only works if object are moved via the physic engine ?
I’m saying that because :
I tried to listend collisions with “dynamic” object and no gravity, making objects move on enterframe (via rotate or translate), but no collision event occured… : so my question.

Could you tell me if I’m right or wrong ?

Thx. [import]uid: 9328 topic_id: 12326 reply_id: 78502[/import]

@Antheor I’m pretty sure that collisions work perfectly well irrespective of how the object is moved… be it enterFrame listeners or transitions or using the physics engine, collisions should work… [import]uid: 64174 topic_id: 12326 reply_id: 78509[/import]

Oh; Thx for the answer, I’ll try to see what’s wrong with my code. [import]uid: 9328 topic_id: 12326 reply_id: 78517[/import]

… sorry but no collision event on rotating objects… :

I have dynamic objects rotating around a center, no collision event fire.

But If I set my rotating objects this way : creating a static center plus newJoint( “pivot”, obj, center, screenCenterX, screencenterY), collison events occur ???!!!
(and I did not change anything else (body definitions, mainloop code,…))

The problem is that when using the tricky solution, another strange thing happen : ween setting up my objects ( obj:rotate(90) ), the object is not at 90 (but around 60 …)

So I’m just stuck …

[import]uid: 9328 topic_id: 12326 reply_id: 78532[/import]

Objects collide only if they are in the same group, so check that out…
And I don’t know about the rotation, you might wanna paste some code here [import]uid: 94012 topic_id: 12326 reply_id: 78551[/import]

Thx for your answer, I have checked the same group question.
I prepare a simplified version of my code for submission :slight_smile: [import]uid: 9328 topic_id: 12326 reply_id: 78574[/import]

Hope that works well, thx for the idea. Alternatively to all the above gravity can be set to zero and wont effect dynamic bodies so can be used instead of kinematic, this will mean you will have to do more work to apply movement yet it is an option. Gravity can be recreated with force or x,y position updates with vector mathematics taking into account Delta Time…
[import]uid: 118379 topic_id: 12326 reply_id: 83115[/import]