Help fixing character animation: The Sequel

I can’t determine anything without code. I guess you need to change the animation sequence back to walking when the player lands… and make sure it stays that way until he jumps.

I’m not sure what your personal work flow is, but in my own development, the very traditional and old-school method of simply drawing out things on paper serves me better than anything else. If I sit down and draw a logic flow chart, and think in my head what needs to happen at each step along the way, it makes my coding 1000x easier and cleaner… and I don’t forget things that I might have forgotten by just hashing out code on-the-fly.

Brent

I understand that you need the code, but I don’t want to paste a large block of code and just say “Here you go!”, right now I think the solution would go in the jump function or the collision function. But I am not sure how to implement it. 

Logically it would be setting the sequence to “walk” in the collision function, when the foot sensor enters (“began” phase) of a solid surface. But at that point you wouldn’t want to start playing the walk, just set it to the first frame (unless you have some type of “idle” sequence, in which case you might want to set it to that and start playing that sequence). Only when the player starts walking again, by press of a directional button, would you want to start playing the walk sequence.

Brent

Ok, I will try this out!

Huge thanks to you, Brent! Works fine now, I set the sequence to walk and it works perfectly! Setting it to idle, caused him to look like the character was sliding on a very slippery surface.

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?