Determine Relative Position if Direction is Arbitrary?

Get help using Construct 2

Post » Sat Jun 07, 2014 8:44 pm

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...
Made Cosmochoria - www.cosmochoria.com
Currently working on Slayaway Camp - www.slayawaycamp.com
B
27
S
8
G
3
Posts: 384
Reputation: 5,020

Post » Sat Jun 07, 2014 8:49 pm

Thank you for any help, in advance!
Made Cosmochoria - www.cosmochoria.com
Currently working on Slayaway Camp - www.slayawaycamp.com
B
27
S
8
G
3
Posts: 384
Reputation: 5,020

Post » Sat Jun 07, 2014 9:03 pm

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
What I know would fill a Book , what I don't know would fill a Library
B
37
S
12
G
29
Posts: 331
Reputation: 16,499

Post » Sat Jun 07, 2014 9:13 pm

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....
Made Cosmochoria - www.cosmochoria.com
Currently working on Slayaway Camp - www.slayawaycamp.com
B
27
S
8
G
3
Posts: 384
Reputation: 5,020

Post » Sat Jun 07, 2014 9:19 pm

What if you compared or combined with layer angle
LayerAngle(layer)
Get the angle, in degrees, of a layer.
What I know would fill a Book , what I don't know would fill a Library
B
37
S
12
G
29
Posts: 331
Reputation: 16,499

Post » Sat Jun 07, 2014 9:21 pm

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. :P i always sucked at trigonometry..
Made Cosmochoria - www.cosmochoria.com
Currently working on Slayaway Camp - www.slayawaycamp.com
B
27
S
8
G
3
Posts: 384
Reputation: 5,020

Post » Mon Jun 09, 2014 5:14 pm

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.
Made Cosmochoria - www.cosmochoria.com
Currently working on Slayaway Camp - www.slayawaycamp.com
B
27
S
8
G
3
Posts: 384
Reputation: 5,020


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 19 guests