# Set an animation frame between angles using 8Direction

0 favourites
• 7 posts
From the Asset Store
Selection frame like in RTS games, works both on mobile and desktop devices.
• I've been trying to figure this out all night and its driving me insane. I've read the tutorials on isometric and on 8Direction animation and i can't get what i'm looking for.

I have 8 individual frames (i've put them on in one image for this post, but they're separate frames. I also, messed up and switched frame 5-6 in the illustration)

[attachment=2:2dmrw7in][/attachment:2dmrw7in]

All I want is for the animation frames to line up properly with which key was pressed.

I have it so the first frame is facing right and is set to 0° so, I figured if i broke 360° into 45° chunks i could check the players angle and have it snap to the frame.

[attachment=1:2dmrw7in][/attachment:2dmrw7in]

The images were rendered out in Blender with the camera set to 45° isometric angle. so, i'd like the sprite to stay heads up and change the frame based on the angle for all 8 directions.

Could anyone help me with this?

• You have 7 angles, so 360/7= 51

Lets say at angle 0 the animation would be frame 0 if you renamed the frames from 0-6 rather than 1-7

If we were to say the angle was 180 we could say that the angle/51 = 3, or the 4th frame.

The frames system is pretty good at rounding things, but it would be wise to get just the whole numbers using int().

Edit:

Just realised you are using 8 frames. Didn't see them all, forum scrolls images.

So divide by 8 rather than 7.

• Yeah, but 360 / 8 = 45° which is what i am currently doing. with the, "is between" conditions in the OP. If i'm misunderstanding, could you post an example possibly? Like I said, I've tried doing it multiple ways even using flags so when 'W' and 'D' or 'A' are pressed together, switch to NE or NW frame.

• No need for the comparison.

Just set the frame to the angle

frame = int(angle/45)

• okay, so i've done what you said with setting the frames based upon the angle (0/45,45/45,90/45,135/45...etc)

Where I'm confused is, what should the condition be since we are no longer comparing if the player is within a range of angles? Sorry if this seems obvious, i'm just not getting it.

[attachment=0:21p0ye01][/attachment:21p0ye01]

• You're using angles wrong. They go from -180 to 180. Change the numbers and it should work fine. Remember that, for the left direction you should check for less than -157.5 OR greater than 157.5!

• ## Try Construct 3

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

Construct 3 users don't see these ads
• There is only one event.

sprite set frame to int(sprite.angle/45)

That would only apply if say you were using angle(x1,y1,x2,y2).

• 7 posts