Collision Problem with Physics

Hi, i am developing a game which include a player on the way and oncoming obstacles.I want to detect collision between coming obstacles and my player. I set physic like that

local physics = require("physics");  
physics.setDrawMode("hybrid");  
physics.start();  
physics.setGravity(0,0);  

Player’s Physics body

  
local physics = require("physics")  
  
 physics.addBody(player, "static");  
 player.density = 1.0;  
 player.friction = 0.3;  
 player.bounce = 0.2;  
 player.isBullet = false;  
 player.isSensor = true;  
 player.isAwake = true;  
 player.isFixedRotation = true;  
 player.isSleepingAllowed = false;  
 player.name = "player";  
 function player:onObstacleHit(event)  
 print("HIT!");  
 end  

Obstacle Physics body

  
local physics = require("physics");  
 physics.addBody(obstacle, "dynamic");  
 obstacle.density = 1.0;  
 obstacle.friction = 0.3;  
 obstacle.bounce = 0.2;  
 obstacle.isBullet = true;  
 obstacle.isSensor = true;  
 obstacle.isAwake = true;  
 obstacle.isFixedRotation = true;  
 obstacle.isSleepingAllowed = false;  
  
 function onHit(self, event)  
 if (event.phase == "began") then  
 print("ON HIT IN OBSTACLE!");  
 event.other:onObstacleHit();  
 end  
 end  
  
 obstacle.collision = onHit;  
 obstacle:addEventListener("collision", obstacle);  
  
 obstacle.name = "obs";  

1 - If i dont set gravity and left it as default, collision detection works perfectly but obstacles falls faster by gravity.
(I want to control moving them, not by gravity)
2 - Even i set physics body as isSensor = true ; when i print that property it shows as nil.

I just want to detect hit by physics but i dont want gravity or any other forces to effect my objects. How can i do it?

Thanks in advance! [import]uid: 80068 topic_id: 17851 reply_id: 317851[/import]

[lua]object.isFixedRotation = true[/lua]

Apply that to any object you don’t want rotating on collision.

Alternatively make them static sensors.

Peach :slight_smile: [import]uid: 52491 topic_id: 17851 reply_id: 68147[/import]

i already did like you said as you see on the code above but it doesnt detect collision if i set gravity to zero. Maybe it does not work because dynamic bodies of obstacles goes to sleep when gravity is zero even i set isAwake=true ?? [import]uid: 80068 topic_id: 17851 reply_id: 68152[/import]

Did you try something like this?
[lua] physics.setScale( 21 )
physics.setGravity( 0, 0 ) – no gravity vector[/lua]
[import]uid: 12704 topic_id: 17851 reply_id: 68153[/import]

i solved it just about isSensor return nil if it’s initialized only in object’s own class.This is not about my code : http://developer.anscamobile.com/reference/index/bodyissensor

it is simply

  
local function onLocalPreCollision( self, event )  
  
 local object = event.other;  
 object.isSensor = true;  
 print("Collision");  
 --Also i can set gravity to zero..  
 end  
 player.preCollision = onLocalPreCollision;  
 player:addEventListener("preCollision",heroCar);  
  

player:

  
\_G.physics.addBody(player, "dynamic");  
player.isFixedRotation = true;  
  

obstacle:

\_G.physics.addBody(obstacle, "kinematic"); obstacle.isFixedRotation = true; [import]uid: 80068 topic_id: 17851 reply_id: 68159[/import]