Sprite movement 8 Dir troubles

Get help using Construct 2

Post » Sat Dec 17, 2011 5:00 am

There doesn't seem to be a lot of documentation on this. I'll use an examples on this. Any I've found deal with 1 sprite top down and the 360 rotation. Do I really need dozens of events to cover 8 dir movement with say for example one of the tank sprites from the sprite pack? Even doing so with that there seems to be issues with movement when multiple keys become involved.

I played with the tank sprites a bit to see what i could accomplish as far as the events and the animation/movement system but it's buggy at best when dealing with a full 8 directions. Something tells me it's more to do with me, but again there isn't much reference I've found.

So far it seems I'd need minimum of 16 events and 16 animations to accomplish this. (and it would be buggy dependant on what key combinations you may be using to control certain diagonal movements.)

Any thoughts, insight or various reference would be greatly appreciated.
B
5
G
2
Posts: 18
Reputation: 1,286

Post » Mon Dec 19, 2011 11:10 pm

B
79
S
24
G
54
Posts: 4,746
Reputation: 40,755

Post » Tue Dec 20, 2011 3:01 am

OMG That's simpler then I would have imagined. Sorry bout the vagueness of the question. After re-reading it I had to stop and go uhhhhh. Again that's exactly what I was talking about. I really appreciate the response, thanks again! :)
B
5
G
2
Posts: 18
Reputation: 1,286

Post » Sun Mar 10, 2013 12:51 am

I've been looking for a way to have smooth transitions in my player's 8 way movement. The problem is I need to put some frames in between each of the 8 directions. I'd probably need 32 total (8 directions plus 3 frames in between them).

If @R0J0hound or someone else could explain what each part of this code is doing so I could adjust it for my needs, it would be greatly appreciated.

The code is int(((Sprite.8Direction.MovingAngle+360+22.5) %360)/45)

Much thanks.
B
40
S
11
G
6
Posts: 228
Reputation: 6,951

Post » Sun Mar 10, 2013 1:55 am

So the MovingAngle is the current angle, but it could be negative, so you add 360 to ensure it isn't. I'm assuming you add 22.5 to force it to choose one higher (a rounding effort) and then you mod it by 360 to get it in range (0-359). You divide it by 45 to see which animation you should be showing because there are 8 directions, and 8*45 = 360.

If you really want 32 animations you'll need to divide by 11.25, and instead of 22.5 you'd add 5.625

(I could be totally wrong too!) BUT I am right in saying your game and your hero sprite are wonderful!cincipon2013-03-10 01:56:21
B
6
S
1
G
1
Posts: 70
Reputation: 702

Post » Sun Mar 10, 2013 2:18 am

Sprite.8Direction.MovingAngle is a value between -180 and 180.
(Sprite.8Direction.MovingAngle + 360) % 360 converts it to a value between 0 and 360

360 / 45 = 8
int(angle / 45) converts an angle between 0 and 360 to a number between 0 and 8

int((Sprite.8Direction.MovingAngle + 360) % 360) / 45
gives you this:


Frame 0 would be between 0 and 45 degrees, really you want frame 0 to be between -22.5 and 22.5 so you want to rotate the entire thing 22.5 degrees. That's where the 22.5 comes from:
B
54
S
28
G
18
Posts: 1,520
Reputation: 25,020

Post » Sun Mar 10, 2013 3:59 am

I would absolutely love to see more threads like this. Explaining the equations, and seeing the diagram Rojo put up, makes understanding the math a little easier. Math gives my brain the hiccups. Once I can visualize what is actually happening, it starts making sense.
B
20
S
2
Posts: 257
Reputation: 2,431

Post » Sat Sep 28, 2013 10:11 pm

How do you do this with mobile touch controls rather than keyboard? Any tricks to do simple one action?
Check out my games on Google Play:

BEAST ATTACK (500,000+ downloads!)

ASTROJUMP
B
34
S
8
G
1
Posts: 398
Reputation: 3,499


Return to How do I....?

Who is online

Users browsing this forum: fredriksthlm, MPPlantOfficial and 20 guests