Physics Help

It’s my first time using physics and I’m running into an issue.

My app is a top down view of the game map. When the user taps the screen the player object will start moving (via transition.moveTo). I have are invisible display.rect objects scattered throughout the map and when the player object collides with one it automatically changes direction.

So I have the player object setup as a dynamic body

physics.addBody( player, {density=0, friction=0.0, bounce=0.0 } )

and I have the invisible boxes set up as static sensor bodies

physics.addBody( hitBox, static, {isSensor = true} )

From the documentation I thought that when something is made a sensor on the collision effect will trigger, nothing physical. However when my player object collides with the hitBox, the hitBox is moved a few pixels.

I even tested it so the collision function did nothing, and when the player object passed through the hitBox, the hitBox moves a little bit.

Is there any way to stop the hitBox from moving at all?

Hi @AppOwlDev,

First of all, you need to define the body type as a string… “static” (in quotes), not static without quotes.

Also, note that when you’re combining physics with transitions, you might need to handle those transitions when a collision occurs. For example, if the player is supposed to change direction or stop when it collides with a “hitBox”, you’ll need to cancel the current transition and take the proper action. Otherwise, you might be using transitions to fight against the natural physical behavior of the physics engine.

Take care,

Brent

The missing quotes were the issue!

Going from a business app (Mostly UI) programming to using physics in a game is a huge difference, heh.

Hi @AppOwlDev,

First of all, you need to define the body type as a string… “static” (in quotes), not static without quotes.

Also, note that when you’re combining physics with transitions, you might need to handle those transitions when a collision occurs. For example, if the player is supposed to change direction or stop when it collides with a “hitBox”, you’ll need to cancel the current transition and take the proper action. Otherwise, you might be using transitions to fight against the natural physical behavior of the physics engine.

Take care,

Brent

The missing quotes were the issue!

Going from a business app (Mostly UI) programming to using physics in a game is a huge difference, heh.