How do I touch to move my platformer avatar?

Get help using Construct 2

Post » Fri Jun 20, 2014 2:36 am

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!
B
8
S
2
Posts: 32
Reputation: 587

Post » Fri Jun 20, 2014 4:09 am

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.
You do not have the required permissions to view the files attached to this post.
Last edited by FragFather on Fri Jun 20, 2014 4:18 am, edited 1 time in total.
B
40
S
12
G
11
Posts: 331
Reputation: 7,752

Post » Fri Jun 20, 2014 4:16 am

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.
B
60
S
10
G
10
Posts: 1,013
Reputation: 9,155

Post » Fri Jun 20, 2014 5:10 am

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:
stupidissues.png

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!
You do not have the required permissions to view the files attached to this post.
B
8
S
2
Posts: 32
Reputation: 587

Post » Fri Jun 20, 2014 1:01 pm

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 ;)
Image Image iTunes: Match3 | Google Play: Match3
B
103
S
37
G
31
Posts: 1,164
Reputation: 28,918

Post » Fri Jun 20, 2014 4:30 pm

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!
B
8
S
2
Posts: 32
Reputation: 587

Post » Fri Jun 20, 2014 11:57 pm

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.
You do not have the required permissions to view the files attached to this post.
B
40
S
12
G
11
Posts: 331
Reputation: 7,752

Post » Sat Jun 21, 2014 12:26 am

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).
B
40
S
12
G
11
Posts: 331
Reputation: 7,752

Post » Sat Jun 21, 2014 12:41 am

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.
You do not have the required permissions to view the files attached to this post.
B
40
S
12
G
11
Posts: 331
Reputation: 7,752

Post » Mon Jun 23, 2014 9:15 pm

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.

Solution.png
You do not have the required permissions to view the files attached to this post.
B
8
S
2
Posts: 32
Reputation: 587


Return to How do I....?

Who is online

Users browsing this forum: t redeemed t and 28 guests