body.bodyType for projectiles and collision objects in platformer style game?

I’m in a quandry. I’m working on a platformer and need to figure out how to get my projectiles that my characters shoot to collide with the static objects I’m using to build my map/environment.

Since this game is a side viewed platformer, I’m using gravity in it.

The collision objects (block based tiles) that I build my maps with are bodyType “static” so that they don’t “fall” based on the gravity of the environment.

In order for my projectiles to shoot “straight”, I’ve had to set them as bodyType “kinematic”. These kinematic bullets hit my bodyType “dynamic” NPCs but don’t collide with my “static” walls.

What’s the best approach to solving this dilemma? If I make my projectiles dynamic they collide with both NPCs and collision objects but they “fall” due to gravity. If I keep them as kinematic, they fly through all of the static set walls in the environment.

Thanks for any advice anyone can offer :slight_smile:

[import]uid: 105707 topic_id: 33743 reply_id: 333743[/import]

Hello @EHO,
This is a classic dilemma in Box2D, and to this point, I haven’t managed to solve it. However, I just chatted with the physics guru on the Corona team, and he indicates there’s a solution. I should have an answer by the end of the weekend.

Regards,
Brent
[import]uid: 200026 topic_id: 33743 reply_id: 134246[/import]

Hi Brent,

I appreciate the info and follow up on this. Although I would love to have discovered that there was a solution to implement this moment, I’m glad to know that my grasp of things are enough to have not missed some key element.

In the mean time, perhaps I should try a non physics based solution? I’m using physics because it makes things easy to set up but there do seem to be some other options. This tutorial by Rob Miracle looks promising:
http://omnigeek.robmiracle.com/2011/12/14/collision-detection-without-physics/

Please keep me posted as to what you discover in house. My effort so far is very promising and if I solve this issue, it’s likely this prototype will end up being my first app that I publish.

Thanks :slight_smile:

PS - glad to see that you’ve moved into a more “official” role, you’ve been very helpful on other issues [import]uid: 105707 topic_id: 33743 reply_id: 134272[/import]

Hi there,

I believe you can make your bullets “dynamic” and then set their gravityScale to zero using http://docs.coronalabs.com/api/type/Body/gravityScale.html.

Hope this helps.

  • Andrew [import]uid: 109711 topic_id: 33743 reply_id: 134274[/import]

Yes! object.gravityScale = 0 does the trick.

Thanks for sharing this tip Andrew, I’m past this roadblock and on my way :slight_smile: [import]uid: 105707 topic_id: 33743 reply_id: 134280[/import]

Great to hear EHO, and thank you Andrew. This “gravityScale” property must have been added to Corona fairly recently because I never knew it existed until now. Maybe it was implemented in the (somewhat recent) Box2D upgrade. I had actually been hoping for such a property for awhile, and now we have it!

Brent [import]uid: 200026 topic_id: 33743 reply_id: 134284[/import]

Yes, it was added in build 873 (released August 7th) as part of the Box2D upgrade to v2.2.1. but without much fanfare:

“Upgrade Box2D to v2.2.1. Added ‘gravityScale’ property to Body. Added several new properties to joint types (see corresponding daily build API docs under type ‘Joint’) — note joint types are more sensitive to mass ratio differences exceeding 10:1.”

The alternative solution, which I had been using previously, was to set my gravity overall to zero, and then manually apply a downward gravity force each frame, in an enterFrame event, to the physics bodies that I wanted to experience gravity. That worked quite well, thought gravityScale is even easier.

  • Andrew [import]uid: 109711 topic_id: 33743 reply_id: 134291[/import]

Hello @EHO,
This is a classic dilemma in Box2D, and to this point, I haven’t managed to solve it. However, I just chatted with the physics guru on the Corona team, and he indicates there’s a solution. I should have an answer by the end of the weekend.

Regards,
Brent
[import]uid: 200026 topic_id: 33743 reply_id: 134246[/import]

Hi Brent,

I appreciate the info and follow up on this. Although I would love to have discovered that there was a solution to implement this moment, I’m glad to know that my grasp of things are enough to have not missed some key element.

In the mean time, perhaps I should try a non physics based solution? I’m using physics because it makes things easy to set up but there do seem to be some other options. This tutorial by Rob Miracle looks promising:
http://omnigeek.robmiracle.com/2011/12/14/collision-detection-without-physics/

Please keep me posted as to what you discover in house. My effort so far is very promising and if I solve this issue, it’s likely this prototype will end up being my first app that I publish.

Thanks :slight_smile:

PS - glad to see that you’ve moved into a more “official” role, you’ve been very helpful on other issues [import]uid: 105707 topic_id: 33743 reply_id: 134272[/import]

Hi there,

I believe you can make your bullets “dynamic” and then set their gravityScale to zero using http://docs.coronalabs.com/api/type/Body/gravityScale.html.

Hope this helps.

  • Andrew [import]uid: 109711 topic_id: 33743 reply_id: 134274[/import]

Yes! object.gravityScale = 0 does the trick.

Thanks for sharing this tip Andrew, I’m past this roadblock and on my way :slight_smile: [import]uid: 105707 topic_id: 33743 reply_id: 134280[/import]

Great to hear EHO, and thank you Andrew. This “gravityScale” property must have been added to Corona fairly recently because I never knew it existed until now. Maybe it was implemented in the (somewhat recent) Box2D upgrade. I had actually been hoping for such a property for awhile, and now we have it!

Brent [import]uid: 200026 topic_id: 33743 reply_id: 134284[/import]

Yes, it was added in build 873 (released August 7th) as part of the Box2D upgrade to v2.2.1. but without much fanfare:

“Upgrade Box2D to v2.2.1. Added ‘gravityScale’ property to Body. Added several new properties to joint types (see corresponding daily build API docs under type ‘Joint’) — note joint types are more sensitive to mass ratio differences exceeding 10:1.”

The alternative solution, which I had been using previously, was to set my gravity overall to zero, and then manually apply a downward gravity force each frame, in an enterFrame event, to the physics bodies that I wanted to experience gravity. That worked quite well, thought gravityScale is even easier.

  • Andrew [import]uid: 109711 topic_id: 33743 reply_id: 134291[/import]