Hi All
would like a character walk around and have collisions with static walls, but if i set my character to static they have no visible collisions, but if i set my character to dynamic the collisions are great but my sprite rotates as in collides?
– Physics Engine
local physics = require “physics”
physics.start()
physics.setGravity(0, 0)
local player = display.newImage(“beer.png”)–display.newRect(display.contentWidth*0.5,display.contentHeight*0.5,32,32)
player:setFillColor(53, 115, 47)
player.name = “player”
player.x = 100
player.y = 100
–physics.addBody(player, {isSensor = true})
physics.addBody( player, “dynamic” , { density=0.0, friction=0, bounce=0 } )
–player:setStrokeColor(180, 180, 180)
local walls = display.newGroup()
local function AddWall(x,y,w,l)
walls:toFront()
local wall = display.newRect(x,y,w,l) --display.newImage(“beer.png”)
wall.name = “wall”
–wall.x = math.floor(math.random() * (display.contentWidth - 32))
–wall.y = math.floor(math.random() * (display.contentHeight - 32))
physics.addBody(wall, “static”, {density = 0.0, friction = 0, bounce = 0})
walls.insert(walls, wall)
end
AddWall(50,50,32,32)
local posx = 0
local posy = 0
local function MovePlayer()
player.x = player.x + posx
player.y = player.y + posy
if player.y < 0 then
player.y = 100
level2()
end
end
Runtime:addEventListener( “enterFrame”, MovePlayer );
local left = false
local right = false
local function ControlPlayer(event)
if event.x < player.x then
left = true
right = false
posx = -3
elseif event.x > player.x then
right = true
left = false
posx = 3
else
posx = 0
end
if event.y < player.y then
posy = -3
elseif event.y > player.y then
posy = 3
else
posy = 0
end
if event.phase == “ended” then
posx = 0
posy = 0
left = false
right = false
end
end
Runtime:addEventListener( “touch”, ControlPlayer )