Here I have two excerpts of functions for collision, both laid out in what was the most logical way I could come up with at the time. Every if/then statement is denoted with a comment underneath to tell you whats what.
The problem comes when the Player runs into the Box object. I want the character to be able to run off of the top of the box, disabling movement(for which I use setLinearVelocity) so they cant continue moving in the air. The problem I have right now is that if they run off of a box, they can continue holding the right/left move buttons and will slowly fly over to the side of the screen. If they run into the side of the box with the last line of code enabled, it disables movement even when theyre on the ground.
The simplest solution I could come up with was to create two physics objects, one for the top of the box and one for the main lower portion. The problem with that is that if I have multiple objects, it will get annoying really fast. Is there any other way around my issue?
function onLocalCollision(self,event)
if event.phase == "began" and event.target.type == "player" and event.other.type == "land" then
onGround = "true"
--Touched land, he is on ground
elseif event.phase == "began" and event.other.type == "player" then
jumped = "false"
--Touched land, jump is no longer active. This line appears that it might be redundant.
elseif event.phase == "ended" and event.target.type == "player" and event.other.type == "land" and jumped == "true" then
onGround = "false"
--Jumped, no longer on ground
elseif event.phase == "ended" and event.other.type == "player" and jumped == "false" then
onGround = "false"
--Lost contact with land with no jump, e.g. running off of a cliff
end
end
function box(self,event)
if event.phase == "began" and event.other.type == "player" and jumped == "true" then
jumped = "false"
onGround = "true"
--Jumped onto a box
elseif event.phase == "began" and event.other.type == "player" and jumped == "false" then
onGround = "true"
--Ran into the side of the box
elseif event.phase == "ended" and jumped == "true" then
onGround = "false"
--Jumped off box
--[[
elseif event.phase == "ended" and event.other.type == "player" and jumped == "false" then
onGround = "false"
--Lost contact with box with no jump, ran off of it. The problem is that this triggers when you run into the side of the box as well. With the player still in contact with the "land" object, as that collision has neither began nor ended, causes onGround = false, rendering the player unable to move.
]]--
end
end
[import]uid: 67886 topic_id: 11559 reply_id: 311559[/import]