Guest User

Untitled

a guest
Feb 24th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. // Gravity pulls the player down,
  2. // but the slope of the hill pushes them in another direction.
  3.  
  4. static const float G = ...; // Acceleration due to gravity.
  5.  
  6. // First find what percentage of gravity is wasted opposing the ground normal:
  7. float dotN = Vector3.Dot(groundNormal, -Vector3.up);
  8. // Or simplified, just -groundNormal.y
  9.  
  10. // Subtract that from the down vector to get the percent
  11. // That pushes the player along the ground plane.
  12. Vector3 tangent = -Vector3.up - groundNormal*dotN;
  13.  
  14. // If you just want an uphill/downhill value, then dot with the player's forward direction.
  15. float dotForward = Vector3.Dot(player.forward, tangent);
  16.  
  17. // Multiply that value by some constant to get their acceleration/deceleration.
  18. Vector3 accel = ACCEL*dotForward*player.forward;
  19.  
  20. // Multiply dotN by some percent and subtract that for friction.
  21. accel -= FRICTION*dotN*player.forward;
  22.  
  23. // Multiply their current velocity by some coefficient and subtract for drag.
  24. accel -= DRAG*player.velocity.magnitude*player.forward;
Add Comment
Please, Sign In to add comment