i am making a simple game similar to papiwall, i need help where you can only apply a linear impulse to the ball when it is touching the ground
i want to prevent it from continuously going up every time you touch it and only when it is on the ground.
here is what i have so far
[code] localGroup = display.newGroup()
localGroup.x = 0
local physics = require(“physics”)
physics.start()
display.setStatusBar( display.HiddenStatusBar )
–objects
local myCircle = display.newCircle( 300, 300, 30 )
myCircle:setFillColor(128,128,128)
local myRectangle = display.newRect(0, 2000, 8500, 100)
myRectangle.rotation = 20
myRectangle.strokeWidth = 3
myRectangle:setFillColor(140, 140, 140)
myRectangle:setStrokeColor(180, 180, 180)
–set physics
physics.addBody(myCircle,“dynamic”, {bounce=0, density=.4, friction=.1})
physics.addBody(myRectangle, “static”, {bounce=0, friction=.1})
–add in group
localGroup:insert(myRectangle)
localGroup:insert(myCircle)
–functions
local function moveCameray(event)
if myCircle.y > 300 then
localGroup.y = -myCircle.y + 400
end
end
Runtime:addEventListener(“enterFrame”, moveCameray)
local function moveCamerax(event)
if myCircle.x > 100 then
localGroup.x = -myCircle.x + 80
end
end
Runtime:addEventListener(“enterFrame”, moveCamerax)
local circleonGround = true
local function onLocalCollision(self, event)
if(event.phase == “began” ) then
if(myCircle == myRectangle) then
circleonGround = true
end
Runtime:addEventListener(“touch”, up)
elseif (event.phase == “ended”) then
end
end
myCircle.collision = onLocalCollision
myCircle:addEventListener(“collision”, myCircle)
local function up(event)
if event.phase == “began” then
if (circleonGround == true) then
myCircle:applyLinearImpulse(0, -20, myCircle.x, myCircle.y)
elseif (circleonGround == false) then
myCircle = nil
end
end
end
Runtime:addEventListener(“touch”, up)
return localGroup
[import]uid: 38977 topic_id: 16169 reply_id: 316169[/import]