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:

1
2
3
4
5
6
7
8
9
10
11
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 )

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

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.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
--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 )

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!

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

i'm not exactly sure if its gonna help you, but try this code of mine:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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>

I just tried your code. Thanks you very much by the way. I can jump off of any object in my game. All of my functions work just as I want them to. It's just this weird collision issue. Here is the first pic anyone has seen of my game: When you push either the left or right button to move the ball and hit the red rectangle and it bounces off the rectangle then the jump button stops working, but the other buttons still function. This happens when ANY object forces the ball away naturally.

http://i1100.photobucket.com/albums/g403/sXcPhallacy/Screenshot2011-12-02at52018PM.png

views:1725 update:2011/12/3 14:45:35
corona forums © 2003-2011