Physics Collisions

Hello, I’m making a  general RPG where you collide with monsters and NPC’s that chase you, and player collides with them. I am using MTE to handle the physics for most of the obstacles(Tiled), I am starting to add monsters/NPC’s, where I wan’t the monsters to never be able to be pushed and never be able to push me. I want the player to never be able to push NPC’s/monsters.

In a quick sum I want my player to stay physics type “static” and NPC/monsters physics type to be “static” so nothing can be pushed around but able to interact with each other, but those both obviously cannot interact with each other through corona. If I change my player to “dynamic” (physics.addBody normal) he sometimes start to shake on walls(annoying) and everything can push him if they are static, and vice-versa. 

If I make them both dynamic type’s, everyone is pushing everyone around and even density doesn’t matter because they can still push each other, I’ve set my guy to 1000 density because values lower still make him jitter in scenarios.

I would like the player to always be “static” to solve a lot of problems as being dynamic the multi layered function of MTE he collides with every layer because walls above and below are static, but having troubles solving this.

Why not make the bodies “sensors” ?

Sounds like that is what you are after. Look up “isSensor” in the physics docs :wink:

making a sprite isSensor = true just prevents any visible collisions from happening to the object which gives me no collision at all. I want static bodies to collide with static bodies, which I know is not possible. I want both objects to not be able to budge but still control them through moveTransitions, as in both cannot push each other being “static” but able to collide with each other.

Sorry, misunderstood. Ok so it sounds like you want to use “collision filters”. Or alternatively, you could look into using “physic contacts”, this lets you disable the visual collision between two objects in a preCollision event, but still have a collision event occur when they are about to collide.

This info is all covered in the physics docs also.

Hope this helps.

Thanks the collision filters helped put me in the right direction, solves a lot of layer problems!

I’m having troubles changing the categoryBits and maskBits in the game

–Where I declare everything at start of main

physics.addBody( player, “dynamic”, { density=10, friction=0, bounce=0, filter = { categoryBits = 2, maskBits = 2 }, shape = playerShape} )

would like to do the code below after certain stuff happens like changing layers I can change my categoryBits,maskBits whenever I want:

player.categoryBits = 3

player.maskBits = 3

But obviously this doesn’t work, having troubles accessing those variables.

Hi Azmar,

You can’t change collision filters after you’ve declared them. You’d need to recreate the bodies if this type of functionality is necessary.

Brent

Why not make the bodies “sensors” ?

Sounds like that is what you are after. Look up “isSensor” in the physics docs :wink:

making a sprite isSensor = true just prevents any visible collisions from happening to the object which gives me no collision at all. I want static bodies to collide with static bodies, which I know is not possible. I want both objects to not be able to budge but still control them through moveTransitions, as in both cannot push each other being “static” but able to collide with each other.

Sorry, misunderstood. Ok so it sounds like you want to use “collision filters”. Or alternatively, you could look into using “physic contacts”, this lets you disable the visual collision between two objects in a preCollision event, but still have a collision event occur when they are about to collide.

This info is all covered in the physics docs also.

Hope this helps.

Thanks the collision filters helped put me in the right direction, solves a lot of layer problems!

I’m having troubles changing the categoryBits and maskBits in the game

–Where I declare everything at start of main

physics.addBody( player, “dynamic”, { density=10, friction=0, bounce=0, filter = { categoryBits = 2, maskBits = 2 }, shape = playerShape} )

would like to do the code below after certain stuff happens like changing layers I can change my categoryBits,maskBits whenever I want:

player.categoryBits = 3

player.maskBits = 3

But obviously this doesn’t work, having troubles accessing those variables.

Hi Azmar,

You can’t change collision filters after you’ve declared them. You’d need to recreate the bodies if this type of functionality is necessary.

Brent