Search Unity

Top Down Wind Physics

Discussion in '2D' started by JapaneseFireBmb, Oct 22, 2020.

  1. JapaneseFireBmb

    JapaneseFireBmb

    Joined:
    Jul 11, 2020
    Posts:
    6
    I'm making a dynamic weather system for a top down pirate game I'm tinkering with. I'm trying to get the wind to push my boats around a little bit. I didn't like the way area effectors seem accumulate force on objects, so I'm trying to do it with rigidbody2d.addforce(). I found and adapted this code I found on another forum:
    Code (CSharp):
    1. Vector3 dir = Quaternion.AngleAxis(currentWindDir - 90f, Vector3.forward) * Vector3.right;
    2.         rigidbody.AddForce(dir * currentWindSpeed);
    The problem is that the boats seem to be getting pushed in any random direction. I have currentWindDIr - 90f because in testing, when I put 0 in for the wind direction, the boats would go straight right. Does anyone see what's wrong with my code? And would you mind explaining to me what's wrong with it please?