Character continuously sliding off the screen, despite collision function repositioning it Please help.

Try this

if event.phase == “ended” then 

            if(event.object1.id == “enemy” and event.object2.id == “character”) then

                showPlayerHit()

                removeOnPlayerHit(event.object1, nil)

            end

        

            if(event.object1.id == “character” and event.object2.id == “enemy”) then

                showPlayerHit()

                removeOnPlayerHit(nil, event.object2)

            end

end 

The problem is back, this only occurs when the character is hit at an angle.

The back of the enemy’s physics box, looks like a bumpy slide.

Both event.phase == “ended” and event.phase == “began” failed to work.

Is there another way to check for multiple collisions?

https://docs.coronalabs.com/daily/guide/physics/collisionDetection/index.html#handling

Global collisions

Thank you for replying, but how can I check for more than one collision, and how can I fix it?

I have tried setting linearVelocity in a Runtime listener, but that does not work.

 if((event.object1.id == "enemy" or event.object1.id == "enemy2" or event.object1.id == "enemy3" or event.object1.id == "enemy4") and event.object2.id == "character") then showPlayerHit() removeOnPlayerHit(event.object1, nil) end if(event.object1.id == "character" and (event.object2.id == "enemy" or event.object2.id == "enemy2" or event.object2.id == "enemy3" or event.object2.id == "enemy4")) then showPlayerHit() removeOnPlayerHit(nil, event.object2) end

This is what I use for my collision.

I have tried to use a function to keep the character in place, but it does not work.

if event.phase == “began” then

               if((event.object1.id == “enemy” or event.object1.id == “enemy2” or event.object1.id == “enemy3” or event.object1.id == “enemy4”) and event.object2.id == “character”) then

                   showPlayerHit()

                   removeOnPlayerHit(event.object1, nil)

               elseif(event.object1.id == “character” and (event.object2.id == “enemy” or  event.object2.id == “enemy2” or event.object2.id == “enemy3” or event.object2.id == “enemy4”)) then

                   showPlayerHit()

                   removeOnPlayerHit(nil, event.object2)

               end

           end

This is my new collision detection code. It still does not work.

Also, I use physics editor for my physics.

Bounce = 0 on both the character and the enemies, so I am not sure what is happening.

Here is the video that shows the problem. The problem occurs at around 40 to 45 seconds and continues until 1:10, I hope this helps.

https://www.youtube.com/watch?v=xGoZ1jEG0YA&feature=youtu.be

Sometimes the character will slide much more than this and disappear off the screen. I just don’t want it to slide at all.

Hi @sdktester15,

What appears to be happening is that, after collision with an enemy, the character is retaining some of the physical force/velocity that occurred from that collision. So even though you’re resetting its X position, it still has physical momentum carried over from the previous collision. This is typical and expected behavior, but fortunately the solution is (or should be) easy: just reset the character’s linear X velocity to 0 on the line directly before you reset its X position:

[lua]

character:setLinearVelocity( 0, nil )

[/lua]

Hope this does the trick,

Brent

Thank you everyone for helping me with this problem, I have solved the problem by simplifying the physics shapes of my enemies, and using Brent’s solution.