2D Zelda like movement

Get help using Construct 2

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
102
Posts: 5,232
Reputation: 67,250

Post » Mon Nov 04, 2013 9:25 am

Very nice trick @R0J0hound, up until now I would test if the angle is between -45 and 45 degres, then between 46 and 135 and so on... Yours is much ore elegant, thank you
B
12
S
5
G
2
Posts: 132
Reputation: 2,627

Previous

Return to How do I....?

Who is online

Users browsing this forum: Baidu [Spider], jaytrott86 and 10 guests