Skip to content

Instantly share code, notes, and snippets.

@ToastHelmi
Last active March 31, 2016 06:12
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ToastHelmi/c75e43871612881e11be to your computer and use it in GitHub Desktop.
Save ToastHelmi/c75e43871612881e11be to your computer and use it in GitHub Desktop.
Add Drag to Boat
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