Collision help

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)

Kinematic objects do not collide with static objects.
You should turn the man to dynamic body.
But you will notice that while you drag the man, he will be affected by gravity.
Here is an awesome solution:
http://kwiksher.com/forums/topic/touch-joints-i-e-dragging-physical-objects/

You create a joint between an event.target.x and the object so the object won’t be affected by gravity.

Hey! So what you could do is set the hero to a dynamic physics body and then do “hero.gravityScale = 0”. Good Luck!

That is also a solution, but creating a joint will make it look more “realsitic”.

Ahh! Well I guess matters what his/hers game looks like.

–SonicX278

Kinematic objects do not collide with static objects.
You should turn the man to dynamic body.
But you will notice that while you drag the man, he will be affected by gravity.
Here is an awesome solution:
http://kwiksher.com/forums/topic/touch-joints-i-e-dragging-physical-objects/

You create a joint between an event.target.x and the object so the object won’t be affected by gravity.

Hey! So what you could do is set the hero to a dynamic physics body and then do “hero.gravityScale = 0”. Good Luck!

That is also a solution, but creating a joint will make it look more “realsitic”.

Ahh! Well I guess matters what his/hers game looks like.

–SonicX278