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

0 favourites
  • 7 posts
From the Asset Store
Rotate & Animation for 16 Direction & Mouse Direction
  • Hi C2 community

    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.

  • 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)).

  • 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?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • 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.

  • 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.

  • 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..

  • 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!

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)