//Is compatible with compound-colliders public static ThicknessData FindThickness(Vector3 origin, Vector3 direction, Func <RaycastHit, bool> isColliderValid, float maxDist = 100, int layerMask = int.MaxValue) { //Damn Linq can be beautiful RaycastHit[] casts = Physics.RaycastAll(origin, direction, maxDist, layerMask) //Forward cast .Union(Physics.RaycastAll(origin + (direction.normalized * maxDist), -direction, maxDist, layerMask)) //Reverse cast .Where(n => isColliderValid(n)) //Only valid colliders .OrderBy(n => Vector3.Distance(origin, n.point)) //Order by distance .ToArray(); Debug.Log($"Num: {casts.Length}"); foreach (var cast in casts) { DrawingFuncs.DrawStar(cast.point, Color.blue, 0.1f, 10); } //Find exit int depth = 0; //For the depth in the colliders for (int i = 0; i < casts.Length; i++) { //We use Vector3.Dot to tell which direction the face is pointing relative to our fire direction depth += (int)Mathf.Sign(Vector3.Dot(direction, -casts[i].normal)); //Damn I love one-liners if (depth == 0) { return(new ThicknessData(Vector3.Distance(origin, casts[i].point), casts[i].point)); } } Debug.Log("Could not find thickness"); //If a proper exit is not found return(default(ThicknessData)); }
public void RenderDebug(decimal deltaTime = -1m, decimal duration = 0.0m, decimal afterDrawDuration = 0.0m) { deltaTime = deltaTime < 0.0m ? (decimal)Time.deltaTime : deltaTime; Debug.DrawRay(Position, Velocity, new Color(0.5f, 0.5f, 0.5f, 1.0f), (float)duration); //Velocity Debug.DrawRay(Position, (Velocity - PrevVelocity) / deltaTime, Color.yellow, (float)duration); //Acceleration Debug.DrawLine(PrevPosition, Position, Color.white, (float)afterDrawDuration); //Delta Position DrawingFuncs.DrawStar(PrevPosition, Color.magenta, 0.5f, (float)afterDrawDuration); //Iteration positions //Directions Debug.DrawRay(Position, Right, Color.red, (float)duration); //X-Direction Debug.DrawRay(Position, Up, Color.green, (float)duration); //Y-Direction Debug.DrawRay(Position, Forward, Color.blue, (float)duration); //Z-Direction }
public void RenderDebug(float deltaTime = float.NaN, float duration = 0.0f, float afterDrawDuration = 0.0f) { deltaTime = float.IsNaN(deltaTime) ? Time.deltaTime : deltaTime; Debug.DrawRay(Position, Velocity, new Color(0.5f, 0.5f, 0.5f, 1.0f), duration); //Velocity Debug.DrawRay(Position, (Velocity - PrevVelocity) / deltaTime, Color.yellow, duration); //Acceleration Debug.DrawLine(PrevPosition, Position, Color.white, afterDrawDuration); //Delta Position DrawingFuncs.DrawStar(PrevPosition, Color.magenta, 0.5f, afterDrawDuration); //Iteration positions //Directions Debug.DrawRay(Position, Right, Color.red, duration); //X-Direction Debug.DrawRay(Position, Up, Color.green, duration); //Y-Direction Debug.DrawRay(Position, Forward, Color.blue, duration); //Z-Direction }
public void Tick(float deltaTime) { //"target is ticking".Log(); velocity += acceleration * deltaTime; position += velocity * deltaTime; //acceleration.Log(); //velocity.Log(); //position.Log(); //deltaTime.Log(); DrawingFuncs.DrawStar(position, Color.red, 5); }