private void UpdateLookAhead() { List <WorldAhead> newWorld = new List <WorldAhead>(); foreach (WorldAhead ahead in worldAhead) { RaycastHit hitInfo; WorldAhead newAhead; if (Physics.Raycast(transform.position, ahead.lookAheadVector, out hitInfo)) { Vector3 transformedLookAhead = transform.TransformDirection(ahead.lookAheadVector); Debug.DrawRay(transform.position, transformedLookAhead, Color.blue, 1.0f, false); newAhead = new WorldAhead(ahead.lookAheadVector, hitInfo); } else { newAhead = new WorldAhead(ahead.lookAheadVector); } newWorld.Add(newAhead); } worldAhead = newWorld; }
// returns Where the first location of obstacle type is detected ahead. Lots of infs if there is not obstacle of type detected ahead. Vector3 WhereAhead(HaggisInteractable.InteractableType type, int maxDist) { for (int i = 0; i < worldAhead.Count && i < maxDist; ++i) { WorldAhead ahead = worldAhead[i]; if (ahead.isHit) { if (ahead.type == type) { return(ahead.position); } } } return(new Vector3(Mathf.Infinity, Mathf.Infinity, Mathf.Infinity)); }
public WorldAhead WhatAhead(HaggisInteractable.InteractableType type, int maxDist) { for (int i = 0; i < worldAhead.Count && i < maxDist; ++i) { WorldAhead ahead = worldAhead[i]; if (ahead.isHit) { if (ahead.type == type) { return(ahead); } } } return(new WorldAhead(new Vector3(0.0f, 0.0f, 0.0f))); }
private void ConstructLookAheadVectors(int count) { worldAhead.Clear(); for (int i = 0; i < count; ++i) { Vector3 lookAhead = Vector3.forward * (((float)i) / 2.0f); lookAhead -= Vector3.up; lookAhead.Normalize(); // create empty world ahead WorldAhead ahead = new WorldAhead(lookAhead); worldAhead.Add(ahead); Debug.DrawRay(transform.position, lookAhead, Color.yellow, 10.0f, false); } }
// returns true if the obstacle type is detected ahead public bool IsAhead(HaggisInteractable.InteractableType type, int maxDist) { for (int i = 0; i < worldAhead.Count && i < maxDist; ++i) { WorldAhead ahead = worldAhead[i]; if (ahead.isHit) { if (ahead.type == type) { return(true); } } else if (type == HaggisInteractable.InteractableType.None) { return(true); } } return(false); }