Collision Detection Issue

When my object touches with multiple physical bodies at the same time my jump button stops working for my character. Say my object is on the ground then runs into a wall while still touching the ground or is being pushed by a joint of any type onto another surface the button stops working. It’s like the game doesn’t know what it’s touching anymore, so he can’t jump. I’m about to go crazy! My game works perfect until this collision error occurs. Please help!
This is everything I’ve tired:
Using Global vs. Local collision listeners
All of the following on my main character and objects
Body.isAwake
Body.isBodyActive
Body.isBuller
Body.isFixed Rotation
Body.isSensor
Body.isSleepingAllowed
I’ve tried switching my bodies from “static” to “kinematic” to dynamic.
I’ve played with the properties i.e. density, bounce, friction. Nothing on all objects.
This guy had the same problem as me I think. I tried what he did and nothing worked:
http://developer.anscamobile.com/forum/2011/02/07/physics-bodies-and-joints-no-collision-detection
Here’s my code for collisions:

[lua]local function onCollision(self, event )

if ( event.phase == “began” ) then
character.canJump = true
elseif ( event.phase == “ended” ) then
character.canJump = false
end
end

character.collision = onCollision
character:addEventListener( “collision”, character )

[import]uid: 46082 topic_id: 18524 reply_id: 318524[/import]

problem is in your event.phase’s
print them and your variable to terminal and you will see whats happening to your object

and you maybe want object to “jump” respond to particular another object [import]uid: 16142 topic_id: 18524 reply_id: 71052[/import]

The way this is set up, your character will be able to jump no matter what it’s touching. If you jump into a wall then you will be able to jump again. If you have something hit the character while in midair it will allow that character to jump again. Basically it will be allowed to jump as long as it’s colliding with anything else.

Maybe giving the items you want it to jump off of a type may be better.

--displays the ground that the character walks on  
local floor = display.newImageRect( blah blah )  
floor.type = "ground"  
  
local function onCollision(self, event )   
 if ( event.phase == "began" and event.other.type == "ground" ) then  
 character.canJump = true  
 elseif event.phase == "ended" and event.other.type == "ground" ) then  
 character.canJump = false  
 end  
end  
   
character.collision = onCollision  
character:addEventListener( "collision", character )  
  

Or something along those lines. Just wrote this online so not sure if it will work, but the general idea of it is it can only be allowed to jump if the character is touching the “ground” and not anything else.
Edit: This may not address your initial concern, just hoping to save you time later on as I realized when I was using the same method, as long as the character was against a wall it could actually scale a wall by constantly jumping in mid air because it was touching something and satisfying the collision listener. [import]uid: 31262 topic_id: 18524 reply_id: 71057[/import]

Thank you guys for responding darkconsoles and aaaron. I’m at work right now and am going to leave early just to try your suggestions. It sounds like you guys may have solved it! I’ll post back ASAP. Thanks again! [import]uid: 46082 topic_id: 18524 reply_id: 71062[/import]

Okay, I tried aaaron’s suggestion, didn’t work. I also tried printing to terminal, but it doesn’t show any errors. I have no idea what is happening. Anybody else have any idea what this could be? It really seems like my game gets confused and just doesn’t give the ability to jump when any physical body touches and repels my character under the games physics and not my controls. Thanks [import]uid: 46082 topic_id: 18524 reply_id: 71140[/import]

i’m not exactly sure if its gonna help you, but try this code of mine:
[lua]local physics =require(“physics”)
physics.start()

local ball = display.newCircle(0,0,30)
ball:setFillColor(255,0,0)

ball.x = 50; ball.y = 50

physics.addBody(ball)

local bound1 = display.newRect(0,0,display.contentWidth, 10)
physics.addBody(bound1, “static”)

local bound2 = display.newRect(display.contentWidth- 10,0,10, display.contentHeight)
physics.addBody(bound2, “static”)

local bound3 = display.newRect(0,display.contentHeight - 10 ,display.contentWidth, 10)
physics.addBody(bound3, “static”)

local bound4 = display.newRect(0,0, 10, display.contentHeight)
physics.addBody(bound4, “static”)
local function jump(self, event)

if event.phase == “ended” then
self:applyLinearImpulse(300, 200, self.x, self.y)
end
end

ball.touch = jump
ball:addEventListener(“touch”, ball)
[lua] [import]uid: 16142 topic_id: 18524 reply_id: 71149[/import]

Can you post your jump function here? It may be an issue there. [import]uid: 31262 topic_id: 18524 reply_id: 71169[/import]

I’ve tried three different ways of jumping and all give the same result, but here is the one I’m using right now.
Edit: I can’t use transitions for jumping. It doesn’t work with my game.

[lua]local jumpButton = function(event)
if circle.canJump then
circle:applyLinearImpulse(0, -18, circle.x, circle.y)

end
end

jumpButton = ui.newButton{
defaultSrc = “button.png”,
defaultX = 250,
defaultY = 200,
onPress = jumpButton,
overSrc = “button.png”,
overX = 230,
overY = 180,
overAlpha = .5,
id = “button”,
text = “”,
font = “Helvetica”,
textColor = { 255, 255, 255, 255 },
size = 16,
emboss = false

}

jumpButton.xOrigin = display.contentWidth-50; jumpButton.yOrigin = display.contentHeight-40
jumpButton.xScale = .4; jumpButton.yScale = .4
jumpButton.alpha = .6
jumpButton.rotation = jumpButton.rotation + 180
jumpButton.isVisible = true
hudGroup:insert( jumpButton )
[import]uid: 46082 topic_id: 18524 reply_id: 71170[/import]

I just tried your code. Thanks you very much by the way. I just can’t get this to work! [import]uid: 46082 topic_id: 18524 reply_id: 71158[/import]

The “circle” item mentioned in your jump function, that should be “character” as mentioned in the first post? Or did you just re-write it for the forum?

Not sure if it will make a difference but your jump function has the same name as your jump button. [import]uid: 31262 topic_id: 18524 reply_id: 71265[/import]