How do I touch to move my platformer avatar?

0 favourites
  • 10 posts
From the Asset Store
Move Block
$10 USD
Captivating puzzle game. With challenging gameplay, this game will keep you very engaged.
  • The game I'm working on is a platformer, ideally what I wanted to do was being able to touch somewhere on the screen and have my avatar run towards the point that I've touched. I've ran into more than a few issues with this, enough to make a forum post about it out of desperation... Since it's a platformer, I couldn't find an efficient way to make it happen with 8-Directional movements or the Bullet behaviour since it still has to interact with my tileset.

    So basically, touch/click and have the avatar move towards that point, with the animations still functioning and such.

    BONUS POINTS: Have a cursor show up where I've touched and have it a static distance from the tiles on the Y-Axis no matter where you touch.

    THANK YOU SO MUCH IN ADVANCE!

  • Here is an example that should do every thing you want.

    To use touch as the platform controls, just check the touch x value against the player x value. If the touch x is greater, simulate pressing right. If it is less, simulate pressing left. It's as easy as that. The only other thing you need to do is account for the jump control. I added an on screen button for that.

  • Did you test the Moveto behavior.

    Search for it in the behavior section, It will help you alot.

    On any touch --- sprite move to (touch.x - touch.y)

    Sprite is moving --- play animation B

    Sprite is not moving --- play animation A.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Thanks for the quick feedback guys!

    But unfortunately it still isn't behaving the way I would want it to...

    FragFather your example was awesome and I tried to tweak it for it to do exactly what I wanted it to do, here's the tweaked event sheet:

    [attachment=0:2endjtl9][/attachment:2endjtl9]

    Basically what I want it to do is to be able to click somewhere without holding down the mouse button and the character gets there on his own, but what actually happens is he goes left by default and I have to hold down the mouse button for him to actually start going the way I want him to, after that when he reaches his destination he spazzes out without actually settling. Also it's cool what you did with the cursor but my tilemap has height variations so it wasn't really functional with what I was trying to do...

    A0Nasser I downloaded the MoveTo behaviour but I couldn't get my character to stick to the ground, if I clicked too high he'd jump up trying to reach where I clicked and on slopes he'd just act weird and choppy. I'll definitely use MoveTo for something else though! Super handy!

    Sorry I'm very needy, but the support so far is great so please help me get this right!

    THANKYOU!

  • I use onScreen controls to let my player move.

    http://envato.wdbase.de/wp-content/demo/platformer/

    Just start the first level to see how it works. Graphics are free and provided from Kenney. If you want to know more just leave a PM <img src="{SMILIES_PATH}/icon_e_wink.gif" alt=";)" title="Wink">

  • I wanted to avoid onScreen controls, personally I think simulating a controller on a touch screen isn't really convenient, thanks for the suggestion though!

  • Alright, here's a modified version. Hope this gets you what you need.

    When it comes to traversing the "height variations" you may need some more events. If you look at the level in the edited version, there is a slope which the player can walk up from the left but not from the right. This is because the slope from the right is too steep. If you are having trouble getting the character to traverse an area, you may want to make sure it is not too steep.

    As for handling platform traversal, an easy way to do it is to add an invisible jump trigger. I re-purposed the jump button as a trigger in this example where if the target is higher than the player when they collide with the trigger, the player will jump. If it isn't higher, the player will just continue walking normally.

    The reason your player "spazzes out" is because you have an exact value set for the location the player is moving to but the player will almost never hit that exact location. That is why in both examples, I have a range of about half the size of the player for the value to be correct (target.x between player.x - 20 and player.x + 20). Adding this simple change will stop the spazzing.

    You don't actually need a global variable to define if the player is moving or not. If you are using the cursor object that you asked to be included, just check the position of the cursor against the player position.

    After looking at your events, there is one thing you should know. The every tick event should only be used if it is the only condition for an event to fire. Using it as a sub event for another condition doesn't change anything. While the parent event is true, the event will trigger every tick without the every tick event. This will help to clean up your code and remove unnecessary events.

  • Well, I just went back and reread the cursor issue. In my second submission, I am just setting the cursor to the position of the touch. I will try to post an example of the cursor in a little bit (if I can figure it out).

  • Well, this is the best you're going to get from me on the cursor issue. This example doesn't work on slopes but it does on any horizontal platform. The key is, the platforms created first must be above those created after them. Other then that, the cursor will show up right above the platform.

    If you can take this example and figure out how to get it to work with slopes, I would love to see it. As for right now though, I don't intend to spend any more time on it.

    I hope it helps and good luck with your project.

  • After many many hours of trying to figure this out I finally found something that works... It's far from perfect but it works so unless anyone has found a better solution this is what I'm going with. Thank you soooo much for the help! I wouldn't of been able to succeed without it.

    [attachment=0:15jun0ye][/attachment:15jun0ye]

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)