How do I rotate an object with different pictures for each.

Get help using Construct 2

Post » Fri May 18, 2018 1:12 pm

Hi!

In my previous top down games, the character looks at the crosshair and the image is rotated accordingly

Now i want to have a view with slight angle (imagine starcraft view), so i need to change character picture depending on what direction the character is looking, not only rotate the character sprite

Brute force solution would be to define single picture sprite animations for each rotation and go
If angle is blabla, set animation blabla
one condition for each picture

Is there a more convenient way to do this?
B
7
Posts: 14
Reputation: 307

Post » Fri May 18, 2018 1:49 pm

I don't think there is a better solution other than comparing the angles and changing animations.

System-> Is between angles -> Character.8Direction.MovingAngle between -45 and 45 : Character set animation frame 0
System-> Is between angles -> Character.8Direction.MovingAngle between 45 and 135 : Character set animation frame 1
etc.
Last edited by dop2000 on Fri May 18, 2018 1:57 pm, edited 1 time in total.
B
19
S
9
G
158
Posts: 2,375
Reputation: 84,377

Post » Fri May 18, 2018 1:53 pm

Thanks!

Thats an upgrade, to use the animation frames instead of changing animations

I guess the frames can be the result of a formula, mapping every degree to a frame number
B
7
Posts: 14
Reputation: 307

Post » Fri May 18, 2018 4:00 pm

But if your sprite has animation, changing only the frame wont work.
B
19
S
7
G
4
Posts: 182
Reputation: 4,194

Post » Fri May 18, 2018 4:13 pm

Right...
any other workarounds?
the interface for multiple animations in one sprite is quite hard-worked.

Could I use numbers as names for animation and change animation via math formula with angle as input?
B
7
Posts: 14
Reputation: 307

Post » Fri May 18, 2018 4:37 pm

Theres no need to set the animation name to numbers, you can use names (strings) and change the animation by the name checking angles.
Just to clarify, you have an isometric game-type, is that it?
In my mind theres no way to achieve this without having animations/drawnings as we're working on a 2d environment.

If you can, wait sometime. Maybe someone has a way.
B
19
S
7
G
4
Posts: 182
Reputation: 4,194

Post » Fri May 18, 2018 4:47 pm

Here is the formula to get the angle in 0-360 degrees range:
a=(Player.8Direction.MovingAngle+360)%360

If you want to have just one formula, I guess you can do something like this to get numeric value 0-3 for player direction:
d = (a>315 | a<=45) ? 0 : (a>45 & a<=135) ? 1 : (a>135 & a<=225) ? 2 : 3

Then set animation frame to d.
Or you can name your animations "A0", "A1", "A2", "A3" and set animation to "A" & d
Image

Did I help to fix a problem in your game? You can buy me a cup of coffee :) If you'd like to hire me, please see this post
B
19
S
9
G
158
Posts: 2,375
Reputation: 84,377


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 58 guests