2D Zelda like movement

Get help using Construct 2

Post » Sun Nov 03, 2013 10:45 pm

In classic Zelda games when you're moving in a direction, and press two other buttons next to it, you keep the same animations just move diagonally in that direction. Example: Moving upwards (play upwards animation), press left arrow (keep playing upwards animation) but move upward diagonally. Here is a video: http://www.youtube.com/watch?v=pV6Vt25qAUs . I did it so if you press a button such as left, and or not pressing any other buttons, it will play left animation and will continue to do so until you let go of left. Then after that the next button you press it will start playing that animation until you let go of it. So if you press up, it will play up animation, and you can press left to move diagonally, but it will keep playing up animation. The problems is, I hold down up arrow, and then press left, then down, he does a weird moonwalk thing. Please help. If you don't understand anything above, can you please just help me come up with a system for good zelda like movement. PS Im using 8 movement control.
B
9
S
1
Posts: 42
Reputation: 622

Post » Sun Nov 03, 2013 10:53 pm

If I understand correctly, I would add an instance variable to the player that indicates the player is moving. Then when a button is pressed, check to see if the player is already moving. If they aren't, set your animation going and set the moving variable

On future button presses, they check to see if moving, and the player is already moving so they skip the animation and press on. You character still moves in the correct directions, but you only set the animation to play if no movement key was being held down prior to the button press.

That should prevent animations from overriding each other, which is what I suspect is happening here. What you have described is "undefined" behavior, meaning the exact outcome depends on which order you test the movement keys determines the final, actual, animation.

At least I think. If what I'm saying doesn't make sense, can you post a .capx? We'll be happy to take a look at it (I wouldn't imagine it would be hard to make a new project, copy the player and the movement key events).

Hope it helps!PixelHero2013-11-03 22:54:20
B
15
S
5
G
2
Posts: 24
Reputation: 2,054

Post » Sun Nov 03, 2013 11:03 pm


[QUOTE=PixelHero] If I understand correctly, I would add an instance variable to the player that indicates the player is moving. Then when a button is pressed, check to see if the player is already moving. If they aren't, set your animation going and set the moving variable

On future button presses, they check to see if moving, and the player is already moving so they skip the animation and press on. You character still moves in the correct directions, but you only set the animation to play if no movement key was being held down prior to the button press.

That should prevent animations from overriding each other, which is what I suspect is happening here. What you have described is "undefined" behavior, meaning the exact outcome depends on which order you test the movement keys determines the final, actual, animation.

At least I think. If what I'm saying doesn't make sense, can you post a .capx? We'll be happy to take a look at it (I wouldn't imagine it would be hard to make a new project, copy the player and the movement key events).

Hope it helps![/QUOTE]

The only issue with that would be going opposite directions. Your system would mean if you were running right then switched to running left, it would keep the right running animation while going left. So you'll need a series of events and sub-events to define when to stick with what animation direction, but it'll work.

I do it based on button presses.

If W is down set animation to north
--subevent: if a, set animation to north,
--if d, north
--if s, south.

Do something like that for each of the four directions and it should cover everything.
B
103
S
38
G
19
Posts: 962
Reputation: 17,986

Post » Sun Nov 03, 2013 11:21 pm

It works fine when I only have left and right. But once I add the vertical movement it glitches.
B
9
S
1
Posts: 42
Reputation: 622

Post » Sun Nov 03, 2013 11:46 pm

Hmmm...Yeah, I was assuming a return to idle before going in the opposite direction (no button press), but there's not necessarily anything in the code to cause that, and it would be bad to assume.

Wouldn't the same thing happen with yours C-7?

If W is down set animation to north
--subevent: if a, set animation to north,
--if d, north
--if s, south.
...
If S is down set animation to south
--subevent: if a, set animation to south,
--if d, south
--if s, north.

then the animation is the north animation, regardless of which key was pressed first.

I think I'm missing something.   


taborgreat, that's probably because of the order of your events. If you reorder them, do you get an issue with a different direction?
B
15
S
5
G
2
Posts: 24
Reputation: 2,054

Post » Mon Nov 04, 2013 3:04 am

I don't get what you mean, but here is the capx so you can see what is happening. BTW, I made the link art. Do you guys like it.

CAPX: http://www.mediafire.com/download/jbz9d32daly73zt/Zelda.capxtaborgreat2013-11-04 03:07:50
B
9
S
1
Posts: 42
Reputation: 622

Post » Mon Nov 04, 2013 3:57 am

I downloaded your capx and played around with it for a while. It will work if you do the following:

For the main event:
If left arrow is down
AND
if down arrow / up arrow / right arrow are not down

Then set animation to walk left.
Then place the sub events exactly as you have them.

Do this for right/down and up as well. This will make it so the animations work correctly in all 8 directions.

You'll still need to add some instance variables or something for when you turn around to make the animations change properly.Burvey2013-11-04 04:02:16
B
60
S
20
G
56
Posts: 1,077
Reputation: 35,941

Post » Mon Nov 04, 2013 5:08 am

Thanks, that helped fix some of the bugs, but I still have problems with the animations transitioning properly. Sometimes I walk walk to the left and the walking right animation plays.
B
9
S
1
Posts: 42
Reputation: 622

Post » Mon Nov 04, 2013 5:09 am

check your other post, I uploaded a capx for you.
B
60
S
20
G
56
Posts: 1,077
Reputation: 35,941

Post » Mon Nov 04, 2013 5:34 am

This topic could be useful:
http://www.scirra.com/forum/sprite-movement-8-dir-troubles_topic47201.html

Anyway discard all your events and i'll show you how to get it working with just two events.

You can get the direction the sprite is moving with the expression:
[code]Link.8Direction.MovingAngle[/code]
You can then convert the angle into a number from 0-3 where
0 right
1 down
2 left
3 up

Here is the formula. it's explained somewhat in the link.
[code]int(((self.8Direction.MovingAngle+360+45) %360)/90)[/code]
One more bit. The numbers 0-3 can be converted to the direction names with this: where "dir" is a integer from 0 to 3.
[code]tokenat("right,down,left,up", dir, ",")[/code]

OK,down to business, add an instance variable to Link and call it "dir". Then make these two events:

Link| 8Direction is moving
--- Link| set dir to int(((self.8Direction.MovingAngle+360+45) %360)/90)
--- Link| set animation to "walk" & tokenat("right,down,left,up", self.dir, ",")

System| Else
--- Link| set animation to "idle" & tokenat("right,down,left,up", self.dir, ",")

B
91
S
31
G
103
Posts: 5,234
Reputation: 67,754

Next

Return to How do I....?

Who is online

Users browsing this forum: blissfulwizard, DevinMurray, wizdigitech, Yahoo [Bot] and 15 guests