[SOLVED] What is the 8 Direction Moving Angle equation?

Get help using Construct 2

Post » Thu Jul 09, 2015 12:17 am

Hi C2 community :D

I'm trying to calculate the angle of an object moved without 8 Direction behavior in relation to another object, but I'm not succeeding.

I tried the formula floor(angle(Self.X,Self.Y,object.X,object.Y)), but didn't work for the end result I want. :(
Last edited by lukezero on Thu Jul 09, 2015 1:34 pm, edited 2 times in total.
B
39
S
9
G
3
Posts: 261
Reputation: 4,361

Post » Thu Jul 09, 2015 12:22 am

Just for the record, I'm wondering that to implement the walking animation of a character not controlled by the player in a isometric 8 directions game.

I'm currently using int(((IA.calc_angle+360) %360)/45), where the instance variable calc_angle is floor(angle(Self.X,Self.Y,object.X,object.Y)).
B
39
S
9
G
3
Posts: 261
Reputation: 4,361

Post » Thu Jul 09, 2015 3:39 am

@R0J0hound, sorry to bother you again, but I tried your formule above, and unfortunately it didn't work for a character just moved by the Move command (with some instance variables).

"walk" & int(((Object.8Direction.MovingAngle+360+22.5) %360)/45)

As said object doesn't use the 8 Direction behavior, you know the best way to apply their walking animations with the angle changes?

The calculations of my instance variables are correct for the character walk animations that move only in diagonal isometric perspective?
Last edited by lukezero on Thu Jul 09, 2015 4:22 am, edited 2 times in total.
B
39
S
9
G
3
Posts: 261
Reputation: 4,361

Post » Thu Jul 09, 2015 3:46 am

I don't quite understand the first bit. Do you want the direction the enemy is moving or the direction from the enemy to the player?

if you're using a behavior they often have a angleofmotion expression or x and y velocity expressions from which you can calculate the angle of motion with angle(0,0,veloctyx,velocityY).

As for calculating a value of 0 to 7 for animation.
This converts a from the range (-180,180) to (0,360):
(a+360)%360
This rounds the angle to the nearest 45degree angle 0 to 7. The 22.5 is half of 45 and is needed to round correctly.
Int((a+22.5)/45)

Edit:
If you are using the move at angle action to move the object then you should keep track of the direction you moved. Another way is to save the objects position to variables oldx and oldy before you move and calculate the angle of motion with angle(oldx,oldy,sprite.x,sprite.y) after you move.
B
94
S
33
G
113
Posts: 5,356
Reputation: 73,273

Post » Thu Jul 09, 2015 3:54 am

To be precise, @R0J0hound, the uncontrolled character follows a trail of fixed pre-established points by command Move with angle and distance calculations basically based on the distance between both. So I used the equation floor(angle(Self.X,Self.Y,object.X,object.Y)).

I'm using the 0-7 calculation, but after some tests, I came to the conclusion that the problem is the lack of connection between the movement and the angle of the object that don't use any behavior.
B
39
S
9
G
3
Posts: 261
Reputation: 4,361

Post » Thu Jul 09, 2015 12:42 pm

lukezero wrote:To be precise, @R0J0hound, the uncontrolled character follows a trail of fixed pre-established points by command Move with angle and distance calculations basically based on the distance between both. So I used the equation floor(angle(Self.X,Self.Y,object.X,object.Y)).

I'm using the 0-7 calculation, but after some tests, I came to the conclusion that the problem is the lack of connection between the movement and the angle of the object that don't use any behavior.


Are you specifying which object you mean in the expression "floor(angle(Self.X,Self.Y,object.X,object.Y))"
I'm guessing there are more than one..
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Thu Jul 09, 2015 1:10 pm

Hi @LittleStain! ^^

The object is a trail Dot that the avatar follows every time.

I managed to solve this problem this morning after the @R0J0hound tip. It was enough after put the calc_angle in the detection event of the next point to be found.

Thanks for the attention and cooperation of always! :D
B
39
S
9
G
3
Posts: 261
Reputation: 4,361


Return to How do I....?

Who is online

Users browsing this forum: Beatchyvon and 18 guests