Object sleeping / collision detection

I’ve got a sprite walking slowly into a brick (composer). The collision detection works when I place the two near but stop working at a distance. It’s a difference of around 5 seconds.

I’ve tried toggling sleeping and awake in both composer and script for both sprite and bricks, but no change, also tried putting these in various locations. I’ve disabled nearly all my code and can’t figure it out. The composer bricks are dynamic.

I’ve run out of ideas on this so help would be amazing :slight_smile:

[lua]

function collisionHandler(self,e)

    print (e.phase … " " … e.name)

    print (“test”)

end


–construct hero man


local heroMan

local function constructHeroMan()

    

    local walkingSheetOptions = {width = 79, height = 101, numFrames = 8}

    local local_walkingSheet = graphics.newImageSheet (“walkingMan2.png”, walkingSheetOptions)

    local sequences_walkingMan1 = 

    {

        {name = “walk”,frames = {1,2,3,4},time = 500,loopCount = 0,loopDirection = “forward”}

    }

    heroMan = display.newSprite (local_walkingSheet, sequences_walkingMan1)

    physics.addBody(heroMan, “static”, {isSensor=true})                                            --<<<<

    heroMan.isSleepingAllowed = false

    --heroMan.isAwake = true

    heroMan.y = 500; heroMan.x = 800

    heroMan:setSequence(“walk”)

    heroMan.name = “heroMan”

    heroMan:play()

    heroMan.collision = collisionHandler

    heroMan:addEventListener(“collision”,heroMan)

        local function animateHeroMan(event)

        heroMan.x = heroMan.x + 1

        end

Runtime:addEventListener(“enterFrame”, animateHeroMan) 

end

constructHeroMan()

[/lua]

you might want to try using the setLinearVelocity API instead of moving your hero object by screen coordinates. This allows the physics system to understand that the object is indeed being handled by the physics engine. Moving a physics object with coordinates isn’t best practice when trying to identify strictly physics interactions.

f.e.:

 local function animateHeroMan() heroMan:setLinearVelocity( 10, 4 ) end animateHeroMan()

Hi @Marcus_01,

One of our ambassadors wrote a tutorial on this just last week, which may be informative for you:

http://coronalabs.com/blog/2015/03/03/tutorial-solutions-to-common-physics-issues/

Take care,

Brent

Thanks Alex, this did resolve the situation. I’m not sure how long it would of taken to figure out! 

Thanks for the link Brent, it makes sense now.  

you might want to try using the setLinearVelocity API instead of moving your hero object by screen coordinates. This allows the physics system to understand that the object is indeed being handled by the physics engine. Moving a physics object with coordinates isn’t best practice when trying to identify strictly physics interactions.

f.e.:

 local function animateHeroMan() heroMan:setLinearVelocity( 10, 4 ) end animateHeroMan()

Hi @Marcus_01,

One of our ambassadors wrote a tutorial on this just last week, which may be informative for you:

http://coronalabs.com/blog/2015/03/03/tutorial-solutions-to-common-physics-issues/

Take care,

Brent

Thanks Alex, this did resolve the situation. I’m not sure how long it would of taken to figure out! 

Thanks for the link Brent, it makes sense now.