Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Now we need to update our get-up position to be roughly wherever we're rolling, if it's safe.
- // First, we calculate the center of the safe-spot (as the centroid of our crash geoms)
- Vector3 newSafePos = Vector3.zero;
- int numGeoms = 0;
- foreach(Collider crashGeom in crashGeoms)
- {
- newSafePos += crashGeom.bounds.center - crashBody.position;
- numGeoms++;
- }
- newSafePos /= numGeoms;
- newSafePos += crashBody.position;
- // If possible, orient the board roughly along the bird's axis when getting back up
- Quaternion newSafeRot = Quaternion.identity;
- if (Mathf.Abs(Vector3.Dot(crashBody.transform.up, Vector3.up)) < GetBackupHere_SteepnessCutoff)
- {
- // The idea is to extract the flat direction the bird's head is roughly pointed in, so bird's up becomes our forward
- newSafeRot = Quaternion.LookRotation((crashBody.transform.up - Vector3.Project(crashBody.transform.up, Vector3.up)).normalized, Vector3.up);
- }
- // Then we want to bump up from there, so that the board definitely has space to drop in
- newSafePos += Vector3.up * GetBackUpHere_OffsetUpFromGround;
- // 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")
- if (!Physics.CheckBox(newSafePos, GetBackUpHere_Box * 0.5f, Quaternion.identity, ourSkateboard.GroundsAgainst))
- {
- getBackUpHere.position = newSafePos;
- getBackUpHere.rotation = newSafeRot;
- getBackUpHere.localScale = GetBackUpHere_Box;
- }
Advertisement
Add Comment
Please, Sign In to add comment