Last active
March 31, 2016 06:12
-
-
Save ToastHelmi/c75e43871612881e11be to your computer and use it in GitHub Desktop.
Add Drag to Boat
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void AddDrag(float area, Vector3 crossProduct, Vector3 centerPoint) | |
{ | |
if (boatRB.velocity != Vector3.zero) | |
{ | |
var angle = Vector3.Angle(crossProduct, boatRB.velocity); | |
if(angle> -90 && angle < 90) | |
{ | |
angle = Mathf.Abs(angle); | |
var areaFactor = Mathf.Clamp(angle, 1, 0); | |
float dragForce = boatRB.velocity.magnitude * boatRB.velocity.magnitude; | |
Vector3 drag = (boatRB.velocity * -1)* 0.5f * density * dragForce * (area * areaFactor); | |
boatRB.AddForceAtPosition(drag, centerPoint); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment