# How do I find out which of two points are upwind or downwind

Get help using Construct 2

### » Fri Feb 24, 2017 8:30 am

Hi,

I am doing a top down sailgame quiz. And for that I need to be able to determine (every tick) which of two points are "Upwind" or "downwind" to the Wind.angle.

I compare the Player.Pos and Enemy.Pos but how to compare that to the Wind.Angle ? Is this the point when I need to look at Trigonometry? I already read about trig. but not entirely sure how to apply that in C2.

Any hint, direction or vector would be appreciated.

Best
John
B
16
S
3
Posts: 12
Reputation: 881

### » Fri Feb 24, 2017 11:40 am

Hmm. Maybe calculate the angle between the player and enemy with
ang = angle(player.x,player.y,enemy.x,enemy.y)

Then use an "angle is within" condition

ang is within 90 degrees of wind.angle
--- player is upwind
B
95
S
34
G
128
Posts: 5,493
Reputation: 81,674

### » Fri Feb 24, 2017 2:55 pm

I set it up like this:

https://dl.dropboxusercontent.com/u/114 ... xample.jpg

But its not working.
B
16
S
3
Posts: 12
Reputation: 881

### » Fri Feb 24, 2017 9:37 pm

B
95
S
34
G
128
Posts: 5,493
Reputation: 81,674

### » Mon Feb 27, 2017 7:51 am

Hi R0j0hound, thanks for the example.

Very interesting and wondering why my own attempt didnt work. However I found a solution, tho not as elegant as yours.

Made two sprites,one with origin at bottom middle, the other at top middle. Then aligned the upwind sprite (origin bottom middle) to wind.angle+90 degress so that the sprite represents the upwind part of the screen. And the same with downwind sprite. They are pinned to player on position only so that they dont turn with the player. Works, but probably uses a lot more resources, which bothers me so will implement this method instead.

Thanks again tho,

John
B
16
S
3
Posts: 12
Reputation: 881

### » Mon Feb 27, 2017 9:22 am

If i understand right. Then you want to know if the enemy is in the 'no go zone' or in the 'go zone'.

When the window blows in a direction (d) then ....
if you take any point in that direction (can be position of the boat) and you face towards the source of the wind (d - 180) ...
then the 'no go' zone is between 45 degrees to your left and 45 degrees to you right.

Any other direction is the 'go zone'.

Or, said another way, standing on the boat, facing direction the source of the wind, the 'no go' zone is between 45 degrees to your left and 45 degrees to you right.

So, using System > Is between angles ... you can NOT sail to the enemy if ...

Angle = angle(boat.x,boat.y,enemy.x,enemy.y) .... (standing on the boat ... looking at the enemy)
First angle = wind.angle - 180 - 45
Second angle = wind.angle - 180 + 45

Using an 'else' gives you the 'go zone'.

System > Is between angles
Else
________ the actions

I guess an invert works too. I did not test this. Code is only in my head.
B
33
S
18
G
29
Posts: 2,493
Reputation: 21,450

### » Mon Feb 27, 2017 9:50 am

Now, lets assume that the enemy is in the 'no go zone'. How do we get there ?

First we need to know which angle to the 'go zone' is the most close.

Left = (wind.angle - 180 - 45) - (angle(boat.x,boat.y,enemy.x,enemy.y))
right = (wind.angle - 180 + 45) - (angle(boat.x,boat.y,enemy.x,enemy.y))

anglediff(left , boat.angle) is smaller then anglediff(right , boat.angle)
____ turn boat left
Else
____ turn boat right

When the boat (turning should go reasonable slow) is at the destination angle (left or right), we can again measure and make a new decision.
B
33
S
18
G
29
Posts: 2,493
Reputation: 21,450