-
-
Save kwalkerxxi/9c3c0284a6217b198a8778a9e533234b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
// @kurtdekker random spawn utilities from my Jetpack Kurt game (And other games) | |
public static class SpawnUtilities | |
{ | |
public static bool ProgressiveLiftAndCastDown( ref Vector3 position, out Vector3 normal) | |
{ | |
Vector3 pos = position; | |
normal = Vector3.up; | |
bool hitGround = false; | |
float castDistance = 0.0f; | |
for (int tries = 0; tries < 250; tries++) | |
{ | |
pos += Vector3.up * 1.0f; | |
castDistance += 2.0f; | |
Ray ray = new Ray( pos, Vector3.down); | |
RaycastHit rch; | |
if (Physics.Raycast( ray, out rch, castDistance)) | |
{ | |
hitGround = true; | |
position = rch.point; | |
normal = rch.normal; | |
var s = "SpawnUtilities.ProgressiveLiftAndCastDown:hit '" + rch.collider.name + "'"; | |
s += System.String.Format( ": pos:{0} norm:{1}", position, normal); | |
Debug.Log( s); | |
break; | |
} | |
} | |
return hitGround; | |
} | |
public static bool ProgressiveLiftAndCastDown( ref Vector3 position) | |
{ | |
Vector3 normalDummy = Vector3.zero; | |
bool hitGround = ProgressiveLiftAndCastDown( ref position, out normalDummy); | |
return hitGround; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment