Help fixing character animation: The Sequel

As you can tell by the ironic title, I have come across another problem with my character animations. Unfortunately, I can’t show the problem because I can only replicate it on my Android device (multitouch stuff, I can only use one finger, AKA, the mouse on the Corona Simulator, and on the phone, I can use two)

The problem looks like this: when I click the left or right button and jump, the character will stay at the end of the jump sequence when it lands. I believe the problem can be fixed with either a “sprite” listener or somewhere in this block of code:

 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 end

Any ideas would be very helpful. 

Thanks in advance!

I tried doing this:

 local function spriteListener(event) print("Sprite event: ", event.target.sequence, event.phase) if event.target.sequence == "jump" and event.phase == "ended" and anim.sensorOverlaps \> 0 then event.target:setSequence("idle") end end anim:addEventListener("sprite", spriteListener)

With unison in this tutorial:

https://docs.coronalabs.com/tutorial/games/allowJumps/index.html

Thanks for starting a new thread on this! (the other one was getting quite long)

Multitouch is a unique thing which you need to handle, and there’s not really “one guide” that can tell you how, because it will depend on each developer’s game. Other than the mention of enabling multitouch in the updated tutorial, I didn’t work that aspect into the actual code… you’ll need to manage that yourself (I can try to help you a bit of course).

I assume you’ve read the multitouch guide so you understand basically what’s involved?

https://docs.coronalabs.com/guide/events/touchMultitouch/index.html

Brent

So are you saying you acknowledged the multitouch but you didn’t add the conditional checks into the tutorial?

Also I had posted another post on the previous topic, but the other one was too long so I am going to post it here:

I have been able to get the character to continue sliding on Live Builds. Here is the APK, so you can see for yourself:

 

https://github.com/sdktester15/SlidingProblem

 

When you have time, please fiddle around with the controls until you are able to get the character to slide. :slight_smile:

Hi again,

I can’t write your multitouch code for you. There are too many factors that vary. You might have things behind the “control panel” that need to be interacted with, and that needs to be handled independently of anything in the controller code.

I worked in some handling for “locking” the touch in the attached project. Before I update the tutorial, please try this project on your actual device and see if you can get the object to continue moving (when it’s not supposed to).

Brent

Hi Brent, the object did not keep sliding which is good. Thank you for all your help so far!

You mentioned that there are many varying factors when it comes to multi-touch, does this include, for instance, handling cases where the player taps shoot and throw at the same time? 

What do you mean behind the “control panel”?

Yeah, multitouch can be tricky. You basically need to decide what controls in your game should be allowed to work together, and which ones can’t.

The code in my updated version should handle multitouch just fine, when on a particular “controller set”. Basically, the first touch on a button (or slide-in) will “lock” that touch to the set, and another touch won’t do anything. So, if you have one set as your directional buttons, it shouldn’t be possible for the user to touch two different arrow keys with two fingers and cause conflict… and that’s how it should be, because they are expected to manipulate that set with just one touch.

If you have another controller set (action buttons) where two might be possible to press at the same time, it will get more tricky because you’ll have to handle that in your code, detecting when both are pressed and taking the proper action in your game. I guess you could just make each one its own “set” but then, you probably don’t want ALL combinations to be possible, like throw and jump at the same time.

Brent

Hmm… I see.

If I recall your previous screenshots, your game control scheme isn’t anything radically different from other platformers right? Set of directional arrows on the left + set of various buttons (jump, etc.) on the right. You should be able to implement two “control sets” and have multitouch work fine.

Brent

Ok. Will the control sets be available on the updated tutorial?

I was actually waiting a bit for you to roll that code (from the zip I sent) into your game, to ensure it takes into account all aspects, before updating the tutorial code…

Brent

Oh ok. I’ll start implementing it.

Ok. I have implemented it. There is good news and bad news. The good news is I can’t replicate the sliding on my device. The bad news is the player now has another error. You see, the way I had fixed that problem before was by adding an if statement at the very top of the function:

 local function functionDirectionalKeys(event) ----if anim.isJumping == false then local touchOverButton = detectKey(event) if event.phase == "began" then if touchOverButton ~= nil then if not directionalKeyGroup.touchID then directionalKeyGroup.touchID = event.id print(event.id) directionalKeyGroup.activeButton = touchOverButton if directionalKeyGroup.activeButton.id == "left" then walk(-1) elseif directionalKeyGroup.activeButton.id == "right" then walk(1) end end return true end elseif event.phase == "moved" then if touchOverButton == nil and directionalKeyGroup.activeButton ~= nil then event.target:dispatchEvent( { name="touch", phase="ended", target=event.target, x=event.x, y=event.y } ) return true elseif touchOverButton ~= nil and directionalKeyGroup.activeButton == nil and touchOverButton.canSlideOn == true then event.target:dispatchEvent( { name="touch", phase="began", target=event.target, x=event.x, y=event.y } ) return true end elseif ( event.phase == "ended" and directionalKeyGroup.activeButton ~= nil ) then directionalKeyGroup.activeButton = nil directionalKeyGroup.touchID = nil anim:setLinearVelocity(0, 0) anim:setSequence("idle") anim:play() return true end return true --end end

But it just so happened that was also causing the sliding. But now I am having the other problem. :frowning:

I can’t record it, but you can replicate it. 

On a post above, I placed a link, that link leads to the .apk file of my project. I replaced with a newer one. If you can, run it, and press the left or right directional key while in mid-air. You will see that it changes its animation sequence in the middle of the jump sequence. I think the reason this is happening is because of my setting the sequence to idle on the ended phase. I am going to try moving the conditional check there.

EDIT: That did not work.

I tested out your APK and there’s definitely something weird. It’s like if you jump and then quickly press “jump” it stops the jump immediately and drops the player back to the ground. However, if I’m already moving before I jump, everything works as expected. That has to be something in your code logic… how you’re handling movement.

Question: why would you want to prevent movement while jumping? Almost every platformer lets you “move in air” to “steer” the jump of the player (physically makes no sense since people can’t change their direction in mid-air, but it works for games lol). So for your game, I think you should just let the player keep “moving in air” while jumping, and then all that really needs to be handled is to ensure that the animation sequence doesn’t turn to “walking” while in-jump.

Brent

I guess I will just do that, however, I need to check up on that other error that you found.

I can see that when I press the left or right button immediately as I jump the character will stop and fall back down.

However, my main concern is the skidding problem, how would I go about fixing that?

I don’t know what your skidding issue is, and I don’t recall seeing it happen when I tested the demo…

That problem can be replicated by doing this:

First, move and then jump, and while still holding the left or right button, wait for the character to land and keep holding the button, you will see that the character is stuck at the end of the jump sequence rather than moving to the walk sequence.

I don’t know your game logic at this point, so there are any number of possibilities. It seems, however, that you have isolated when the issue occurs, and very specifically so… now you need to carefully follow your logic flow and figure out  why. Apparently something is not being set/reset properly when the character lands after a jump (foot sensor collision).

I thought you had solved this long ago, with the sprite sequences and foot sensor. Not sure why it’s coming back now, after implementing the new controller system. The controller system by itself doesn’t have anything to do with sprites, it simply tells you which button is being pressed or not.

Brent

The were two problems sliding and skidding.

The sliding was solved (character keeps moving after letting go of left or right key), the skidding was not (character stays on the end of jump animation if you land while holding the left of right key)