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]
[import]uid: 52491 topic_id: 17851 reply_id: 68147[/import]