Okay, I have been working with corona for about 3 weeks now, and thinks its great! but it has some problems that I have a HARD time getting through. One of these seems to be Physics Bodies. And I just wanted to start a thread where these are THOROUGHLY explained. Because they are driving me crazy, and I think are not very well explained or documented by Ansca (Not complaining!)
So there are three types of physics bodies, we all know that:
Static: Cannot be moved and dont respond to gravity (walls and floors etc)
Kinematic: Can be moved, but dont obey gravity (great for sensors!)
Dynamic: Normal physics bodies, respond to touch and gravity
Then there is the collisions that can happen between them
Static ONLY collides with dynamic
Kinematic ONLY collides with dynamic
Dynamic collides with Dynamic/Static/Kinematic
This is where box2d seems really stupid, because for some reason, they think its easier for EVERYONE to use dynamic objects when clearly gravity is a big factor in designing games. I for one want to use kinematic objects more often, And I know everyone says “Just turn the gravity to 0 and use dynamic”, but I am one to say that it doesn’t always work like that, and almost always complicates things a lot later on.
Then there is the isSensor property, which still doesn’t make a lot of sense to me. From my understanding, its makes that body NOT interact with any other physics object, but still registers collision events, and obeys the same properties of the original body(dynamic/static/kinematic). For example:
A dynamic sensor will still fall from gravity, but will not collide with any static or kinematic objects *Physically*(it will still register collision events)
Or a Kinematic sensor will register collision events, but will not obey gravity, or affect any other normal physics body physically.
So here is where my problem is: I have a couple of dynamic bodies on my stage that I can drag around and throw just fine. They collide with walls and register collision events fine ONLY when they are the ones initiating those events. Then I have a “laser” in the middle of my screen that can rotate all the way around. It is an image that gets shown by changing the “isVisible” property. I have made the image itself a kinematic-sensor. So physics isnt affecting this “laser” in any way. I am rotating it with code.
I have all three bodies attached to a collision function:
[lua]local function laserCollision( self, event )
if(event.phase == “began” ) then
if(event.other.name) then
print(self.name…" with “…event.other.name…” Began")
end
elseif ( event.phase == “ended” ) then
if(event.other.name) then
print(self.name…" with “…event.other.name…” Ended")
end
end
return true;
end[/lua]
And here is what happens:
- When I drag the two dynamic bodies around myself, they register collisions fine! Even with the lazer.
(ie. Square with Laser Began) - When I throw the two dynamic bodies around, they still register fine
- When I rotate the laser around myself, it almost never registers any collision events with EITHER of the dynamic bodies. And when it does register, it is NOT how I expect. It happens when the lazer body isn’t even touching or anywhere near the dynamic body.
(ie. Laser with Square Began)
So all around weird behavior from the laser collisions, and I think this might be because I am manually setting the .rotation property of the image that the body is attached to. But I cant think of a way around it!
-I have tried making the laser static (same behavior)
-I have tried making it dynamic (then it obeys gravity and falls off the screen)
-and YES, I have tried making the gravity 0, but then the menu I am creating acts nothing like it should (I need the dynamic objects to obey gravity)
-I cant make the laser NOT a sensor, because then it reacts weird with the object it is attached to( long story)
So I apologize for the long post, I just wanted to be really thorough, because I know its hard to help someone if you dont know what they need. If anyone has any questions about my problem or additions to the behavior of physics bodies, PLEASE let me know, or reply, because the more info the better. Thank you in advance!
[import]uid: 67379 topic_id: 11713 reply_id: 311713[/import]
Props to