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

0 favourites
  • 7 posts
From the Asset Store
Connect the dots in the correct order and draw happy animals!
  • 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

  • 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

  • I set it up like this:

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

    But its not working.

  • 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

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

  • Try Construct 3

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

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

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