I need help with making a wall collide with an object. i want to drag the object “hero” into the wall and the wall stop it. How can i do this?
local physics = require(“physics”)
physics.start()
–> Remove Status Bar
display.setStatusBar(display.HiddenStatusBar)
–> Half Screen Sizes
halfW = display.contentWidth/2
halfH = display.contentHeight/2
–> Create Background
local background = display.newImage(“pictures/BackgroundWA.png”, halfW, halfH)
background: scale(0.5, 0.5)
–> Set Gameover to False
local gameOver = false
–> Create Hero
local hero = display.newImage(“pictures/YELLOW.png”, halfW, halfH)
hero: scale(0.25, 0.25)
–> Create Walls
local wallLeft = display.newRect(15, halfH, 1, 300)
local wallRight = display.newRect(display.contentWidth-15, halfH, 1, 300)
physics.addBody( wallLeft, “static” )
physics.addBody( hero, “kinematic” )
wallLeft.isbUllet = true
–> Dragging Function
function hero:touch( event )
if event.phase == “began” then
self.markX = self.x – store x location of object
self.markY = self.y – store y location of object
elseif event.phase == “moved” then
local x = (event.x - event.xStart) + self.markX
local y = (event.y - event.yStart) + self.markY
self.x, self.y = x, y – move object based on calculations above
end
return true
end
hero:addEventListener(“touch”, dragging)