Guest User

Untitled

a guest
Dec 8th, 2020
38
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.51 KB | None | 0 0
  1. // Now we need to update our get-up position to be roughly wherever we're rolling, if it's safe.
  2.  
  3. // First, we calculate the center of the safe-spot (as the centroid of our crash geoms)
  4. Vector3 newSafePos = Vector3.zero;
  5. int numGeoms = 0;
  6. foreach(Collider crashGeom in crashGeoms)
  7. {
  8. newSafePos += crashGeom.bounds.center - crashBody.position;
  9. numGeoms++;
  10. }
  11. newSafePos /= numGeoms;
  12. newSafePos += crashBody.position;
  13.  
  14. // If possible, orient the board roughly along the bird's axis when getting back up
  15. Quaternion newSafeRot = Quaternion.identity;
  16. if (Mathf.Abs(Vector3.Dot(crashBody.transform.up, Vector3.up)) < GetBackupHere_SteepnessCutoff)
  17. {
  18. // The idea is to extract the flat direction the bird's head is roughly pointed in, so bird's up becomes our forward
  19. newSafeRot = Quaternion.LookRotation((crashBody.transform.up - Vector3.Project(crashBody.transform.up, Vector3.up)).normalized, Vector3.up);
  20. }
  21.  
  22. // Then we want to bump up from there, so that the board definitely has space to drop in
  23. newSafePos += Vector3.up * GetBackUpHere_OffsetUpFromGround;
  24.  
  25. // If that spot is clear? Cool! Update our get-up position (yes this can be floating in air, because it feels more right than the edge cases you get if you limit it to "last safe spot that was ALSO near grounded")
  26. if (!Physics.CheckBox(newSafePos, GetBackUpHere_Box * 0.5f, Quaternion.identity, ourSkateboard.GroundsAgainst))
  27. {
  28. getBackUpHere.position = newSafePos;
  29. getBackUpHere.rotation = newSafeRot;
  30. getBackUpHere.localScale = GetBackUpHere_Box;
  31. }
Advertisement
Add Comment
Please, Sign In to add comment