Determine Relative Position if Direction is Arbitrary?

0 favourites
  • 7 posts
From the Asset Store
Rotate & Animation for 16 Direction & Mouse Direction
  • Im trying to find out if "Object1" is 'to the left of' "Object2".

    Normally i would just compare their x positions:

    If Object1.X <= Object2.X Then

    isOnLeft = True

    But what about if my direction is arbitrary and camera rotates smoothly so you never really know what way is actually 'up'. Basically My entire layout shifts 180* and now X & Y are opposite...

    Is there a formula or something I could use to account for the 'floating' position so that it's always checking position in relation to whats actually on the screen? ie.. even thought the camera is rotating, the player is always in the center, so things still *appear* to be left and right of him...

    Basically im trying to get enemies to face me when coming at me... though if the camera has rotated upsidedown then they look away from me as they come at me...

  • Thank you for any help, in advance!

  • I have not tried this and don't really know if it will work in your situation but what about

    angle(x1, y1, x2, y2) Calculate angle between two points

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • was playing with that a bit but it doesnt seem to give me a standard number.. ie -- standing to the left of the object had an angle anywhere from -30->400 and standing to the right of it had the same thing... no consistency. i have a feeling its because it's adjusting the angle entirely based on the x & y points so it is also ignoring the actual 'rotation' of the camera as well....

  • What if you compared or combined with layer angle

    LayerAngle(layer)

    Get the angle, in degrees, of a layer.

  • Was thinking of that too, but not sure how to work them together somehow.. working with some paper on my desk to see if i can simulate to see if the math becomes apparent from that. i always sucked at trigonometry..

  • Got it:

    Set PetFacing = angle(0,0,cos(angle(Player.X,Player.Y,Pets.X,Pets.Y)-Player.Angle+90),sin(angle(Player.X,Player.Y,Pets.X,Pets.Y)-Player.Angle+90))

    If PetFacing >= 0

    • Set Mirrored

    Else

    • Set UnMirrored

    Thanks dude - we were on the right track but you got me thinking about it more. NeoGAF helped push me over the edge.

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