Oh yeah, I can just combine the other collisions into this function. :wacko:
Now that it’s local I am seeing some activity, but when I jump this gets printed out:
0 1 2 2 2
Those are the sensorOverlaps…
0, 1 when it goes from ground to air.
2,2,2 when it hits ground.
Did you already change everything into “local” collisions? Note that will change quite a few property names throughout, especially with how you reference things. For example, “event.element1” will become “event.selfElement”, etc.
See here for a comparison:
Yes.
function anim:collision(event) if ( event.selfElement == 2 and event.other.objType == "ground") then if ( event.phase == "began" ) then self.sensorOverlaps = self.sensorOverlaps + 1 self.isJumping = false elseif ( event.phase == "ended" ) then self.sensorOverlaps = self.sensorOverlaps - 1 if self.sensorOverlaps == 0 then self.isJumping = true end end end print(self.sensorOverlaps) end anim:addEventListener("collision")
It appears then you’re getting expected values for “sensorOverlaps” finally. What is the issue at this point?
At this point, it’s still Problem #2, I was having at the top of this post. But, we can leave it for tomorrow. I need a shower. :wacko: Thanks for the help so far!
So, right now I am having another problem. Before, my character was able to jump while it’s moving left or right, but now it can’t. Unfortunately, I am not sure where this is happening.
Also, even though the isJumping flag works well now, it has no effect on my other problem. (Character stutters when pressing left or right in mid-air)
EDIT: I was able to solve this problem, by doing this:
local function makeControls(self, event) if anim.isJumping == false then if event.phase == "began" then if self.name == "left" then walk(-1) elseif self.name == "right" then walk(1) end elseif event.phase == "ended" then idle() end return true end end
But now my character won’t stop moving. Problem #2 fixed, problem #1 is back.
I know why this is happening because if the character is jumping, there is no phase to set the character back to idling. But, I don’t know how to fix it.
So what you’ve done, it appears, is disable all horizontal motion when the character is jumping. I assume that’s not what you want…
Here’s a list of things I would “plan” for a game like this, completely without thinking of your specific code at this time:
-
If character is on the ground (foot sensor touching at least 1 ground piece), he can jump.
-
If character is on the ground, his walking animation can happen when the user presses left or right, along with his actual left/right movement.
-
If character is not on the ground (foot sensor touching nothing), he can not jump again (no “air jumps” for this game).
-
If character is not on the ground (is jumping), his animation sequence can not change from the “jump” sequence.
-
If character is not on the ground (is jumping), his walking motion can happen (for an arched jump pattern) but not his walking animation.
-
Once character re-touches ground, his animation sequence goes back to “idle” (I assume).
This isn’t a complete list by any means, but it’s the main points I would consider when approaching a platformer. Please step through these and see how you’ve handled them in your code.
Brent
-
Check.
-
Check. (Unless the problem occurs)
-
Check.
-
Check. (Just got that to work)
-
Check. (Problem afterward, however)
-
Check. (Unless the problem occurs)
The problem I am talking about in this case is that when the user clicks on a button and drags off of it, the player will keep ‘skidding’ (It will move while staying at the end of the jump sequence). This is because of the way I set up my makeControls function. Though, I don’t know how to fix it.
local function makeControls(self, event) if anim.isJumping == false and anim.sequence ~= "jump" then if event.phase == "began" then if self.name == "left" then walk(-1) elseif self.name == "right" then walk(1) end elseif event.phase == "ended" then idle() end return true end end
This was the same problem I was faced with at the beginning of this post. Thank you for the list, it helped me clarify some issues.
Edited the post above.
Ah, now it’s clearer… you’re encountering the “slide off” issue it seems. When a user touches a directional button, but then “slides off” that button without releasing from the screen, something doesn’t “reset” in your game, correct?
Exactly. The character does not go back to its idling stage. Is this a common problem?
Like most things, “slide off” needs to be handled properly. Sorry I didn’t catch this aspect earlier.
Ironically, I’m working on an improved tutorial on this issue at the moment, but it’s not ready yet.
In the meantime, you should check out the sample project “SampleCode > Hardware > InputDevices” in your Corona application folder. It shows how slide-off can be checked using a 4-directional “virtual d-pad” which is basically what you’re doing here.
Brent
Thanks, I will take a peek.
Where is the slide-off check?
It’s not like a specific built-in event, just look at the “onTouchEvent()” function in “main.lua”. Notice how it uses both “began” and “moved” phases, and then sets a “vector” for the direction based on which button is being pushed. Basically, that makes it so that when you “slide off” one part and onto another, the movement vector changes to the new one being pressed (and thus the previous one doesn’t matter).
Great, but the problem occurs when I slide up and away from the joystick. I don’t slide onto another button, I slide away from all of the buttons, and it keeps moving in that direction.
It would appear I misinterpreted your previous post:
Ah, now it’s clearer… you’re encountering the “slide off” issue it seems. When a user touches a directional button, but then “slides off” that button without releasing from the screen, something doesn’t “reset” in your game, correct?
Test out the demo… notice how it handles when you slide off (say) the “up” direction onto nothing (not another button, off the controller).