How do I Calculate Angle Toward Position?

0 favourites
  • 10 posts
  • hi,

    how do i Calculate angle toward position ?

    in construct 2 we can set that and its good .. but i want to get it and test if my object angle is toward another object position then do something ...

    thanks....

  • I don't know if there's a specific way but if you know the locations of both objects, then the angle is given by the inverse tan of the difference in vertical pixels divided by the difference in horizontal pixels. just be aware of some symmetry problems.

  • Expression "angle(x1, y1, x2, y2)" will calculate angle between two points. Is that what you asked?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Expression "angle(x1, y1, x2, y2)" will calculate angle between two points. Is that what you asked?

    No , i want to Calculate Angle Toward Position of another object ..

    look in this example:

    dl.dropboxusercontent.com/u/5426011/examples%209/turret.capx

    my problem is the turrets fire when they finde the target. but i want they not do that until they rotate toward the target .. like turret behavior

    ....

    i can not use turret behavior because i want to set object with diffrent instance variable as a target

  • mahdi71

    Objects have X and Y values for their position

    So if you had an object Turret and an object Target, using the expression Shinkan suggested you'd do angle(Turret.X, Turret.Y, Target.X, Target.Y) to get the angle from Turret to Target.

    You'd then compare this angle to Turret.Angle to see if it was pointing in the right direction.

  • mahdi71

    Objects have X and Y values for their position

    So if you had an object Turret and an object Target, using the expression Shinkan suggested you'd do angle(Turret.X, Target.X, Turret.Y, Target.Y) to get the angle from Turret to Target.

    You'd then compare this angle to Turret.Angle to see if it was pointing in the right direction.

    actually it should be angle(turret.x,turret.y,target.x,target.y)

  • > mahdi71

    >

    > Objects have X and Y values for their position

    >

    > So if you had an object Turret and an object Target, using the expression Shinkan suggested you'd do angle(Turret.X, Target.X, Turret.Y, Target.Y) to get the angle from Turret to Target.

    >

    > You'd then compare this angle to Turret.Angle to see if it was pointing in the right direction.

    >

    actually it should be angle(turret.x,turret.y,target.x,target.y)

    Ok, so angle(Turret.X, Turret.Y, Target.X, Target.Y) as might be case-sensitive

  • ok ...

    you guys right

    but angle(Turret.X, Turret.Y, Target.X, Target.Y) give me a number less then 0 sometimes like -110 so i add the number to 360 if that number is less then 0 then this solve my problem ... thanks ...

  • mahdi71

    You could also use anglediff(angle1,angle2) when doing the comparison, which should be ok with negative angles.

    Here's an example

    [attachment=0:casp76qk][/attachment:casp76qk]

    Just drag the blue target around and the turret will follow it.

  • mahdi71

    You could also use anglediff(angle1,angle2) when doing the comparison, which should be ok with negative angles.

    Here's an example

    [attachment=0:221ey5kj][/attachment:221ey5kj]

    Just drag the blue target around and the turret will follow it.

    Yes .. its better .. thanks ...

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