Advertisement
Munchy2007

FixedUpdateHoverForce

Mar 17th, 2016
21,226
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.85 KB | None | 0 0
  1.     //  Hover Force
  2.         RaycastHit hit;
  3.         bool  grounded = false;
  4.         for (int i = 0; i < hoverPoints.Length; i++)
  5.         {
  6.             var hoverPoint = hoverPoints [i];
  7.             if (Physics.Raycast(hoverPoint.transform.position, -Vector3.up, out hit,hoverHeight, layerMask))
  8.             {
  9.                 body.AddForceAtPosition(Vector3.up * hoverForce* (1.0f - (hit.distance / hoverHeight)), hoverPoint.transform.position);
  10.                 grounded = true;
  11.             }
  12.             else
  13.             {
  14.                 // Self levelling - returns the vehicle to horizontal when not grounded
  15.                 if (transform.position.y > hoverPoint.transform.position.y)
  16.                 {
  17.                     body.AddForceAtPosition(hoverPoint.transform.up * gravityForce, hoverPoint.transform.position);
  18.                 }
  19.                 else
  20.                 {
  21.                     body.AddForceAtPosition(hoverPoint.transform.up * -gravityForce, hoverPoint.transform.position);
  22.                 }
  23.             }
  24.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement