**First post ever so please excuse any lack of protocols.**
I've remade the code in several versions so I wouldn't know which to post to show my code.
So let's stick with conceptual solutions for now.
**CONTEXT:**
*there is an object (the object this script is attached to)
*this object will cast a ray and mark the hit point
*define the reflection of this ray (direction, blah.normal)
*then a second ray will cast using the hit point of the first ray as its origin and the direction equal to the reflected direction.
*mark the second hit point(with a second raycasthit)
*repeat this a third time to allow for smoother transition(found that out the hard way) **WHAT I WANT TO HAPPEN:**
*the object will MoveTowards the first hit point
*if (objectDistanceFromFirstHitPoint < 2) { MoveTowards second hit point }
*if (objectDistanceFromSecondHitPoint < 2) { MoveTowards third hit point }
*recast first ray off of third ray and continue the pattern(second off of first, third off of second, first off of third, repeat)MY THOUGHTS:
*Hopefully you can tell I know how to code, this is more of a where does everything go kind of question.
*I am also aware that this is not the only way to do this (codewise)
*I did a huge debug to see if i could locate any problems. using UnityEngine; using System.Collections; public class proTest : MonoBehaviour { //create vector3s to hold the reflections public Vector3 hitreflectionDirection; public Vector3 hit2reflectionDirection; public Vector3 hit3reflectionDirection; //create two rays(one for current one for reflection) and raycasthit, a step to convert speed and a bool to cast a new ray Ray ray; Ray ray2; Ray ray3; RaycastHit hit; RaycastHit hit2; RaycastHit hit3; //Setup movement path as true/false booleans public float step = 10f; float locPos = 0; bool fromObject = true; //Allow for the creation of new instances of newray public rayToCast newray = new rayToCast(); //creates the random intergers for vector3 anglingNEEDS WORK! public class rayToCast { //create 3 random intergers to hold a random number between 1 and 360 and use them for random x, y, z coords public int randX = Random.Range(0, 360); public int randZ = Random.Range(0, 360); public int randY = Random.Range(0, 360); } // int path = 0; bool shootRayAisShot = false; bool shootRayBisShot = false; bool shootRayCisShot = false; // void shootRayA () { Debug.Log("shootRayA begins"); //________________________SHOOTA VARIABLES________________________________________ //set the gameobject's position to, "objectLocation" to allow for easy trans.pos Vector3 objectLocation = transform.localPosition; //set a spacer for the ray position(which fires front the front[top] of the capsule) Vector3 raySpacer = new Vector3(0, 0, 1.1f); //Create a vector Direction that takes in a new random vector3 using the random x, y, z coords Vector3 vecDir = new Vector3(newray.randX, newray.randY, newray.randZ); //create and define a random vector3 "rayAngler" to angle the ray, using vecDir to randomize Vector3 angledRayDirection = transform.up.y * vecDir; //Create a float to track the distance from where the fish is to where it is going //float dist = Vector3.Distance(fishLocation, hit.point); Debug.Log("shootRayA variables loaded...functionality begins..."); //________________________SHOOTA FUNCTIONALITY________________________________________ if (fromObject == true) { Debug.Log("fromfish reads: " + fromObject); //Cast a ray from object's location to random angle ray = new Ray(objectLocation + raySpacer, angledRayDirection); Debug.Log("ray new ray is cast with: " + objectLocation + raySpacer); Debug.Log("as origin and direction as: " + angledRayDirection); if (Physics.Raycast(objectLocation + raySpacer, angledRayDirection, out hit)) { Debug.Log("shootRayA if(physics) reads true, hit reads: " + hit.point); Debug.Log("if(physics) is cast with: " + objectLocation + raySpacer); Debug.Log("as origin and direction as: " + angledRayDirection); //find the direction of the reflection of this ray hitreflectionDirection = Vector3.Reflect(ray.direction, hit.normal); Debug.Log("hitreflectiondirection origin is: " + ray.direction); Debug.Log("as ray.direction and normal as: " + hit.normal); Debug.Log("hitreflectiondirection is: " + hitreflectionDirection); // shootRayAisShot = true; } } else { Debug.Log("fromObject else loaded with fromObject reading: " + fromObject); //Cast a ray from hit3.point in the direction of hit3.point's reflection ray = new Ray(hit3.point, hit3reflectionDirection); Debug.Log("fromObject else ray cast with: " + hit3.point); Debug.Log("as origin and direction as: " + hit3reflectionDirection); if (Physics.Raycast(hit3.point, hit3reflectionDirection, out hit)) { Debug.Log("shootRayA else(physics) reads true, hit reads: " + hit.point); Debug.Log("else(physics) is cast with: " + hit3.point); Debug.Log("as origin and direction as: " + hit3reflectionDirection); //find the direction of the reflection of this ray hitreflectionDirection = Vector3.Reflect(ray.direction, hit.normal); Debug.Log("hitreflectiondirection origin is: " + ray.direction); Debug.Log("as ray.direction and normal as: " + hit.normal); Debug.Log("hitreflectiondirection is: " + hitreflectionDirection); // shootRayAisShot = true; } } } void shootRayB() { Debug.Log("shootRayB begins"); //________________________SHOOTB VARIABLES________________________________________ //set the gameobject's position to, "objectLocation" to allow for easy trans.pos Vector3 objectLocation = transform.localPosition; //Create a float to track the distance from where the objext is to where it is going float dist2 = Vector3.Distance(objectLocation, hit2.point); Debug.Log("shootRayB variables loaded...functionality begins..."); //________________________SHOOTB FUNCTIONALITY________________________________________ //Cast a ray from hit.point in the direction of hit.point's reflection ray2 = new Ray(hit.point, hitreflectionDirection); Debug.Log("ray2 new ray is cast with: " + hit.point); Debug.Log("as origin and direction as: " + hitreflectionDirection); if (Physics.Raycast(hit.point, hitreflectionDirection, out hit2)) { Debug.Log("if(physics) is cast with: " + hit.point); Debug.Log("as origin and direction as: " + hitreflectionDirection); Debug.Log("shootRayB (physics) reads true, hit2 reads: " + hit2.point); //find the direction of the reflection of this ray hit2reflectionDirection = Vector3.Reflect(ray2.direction, hit2.normal); Debug.Log("hit2reflectiondirection origin is: " + ray2.direction); Debug.Log("as ray2.direction and normal as: " + hit2.normal); Debug.Log("hit2reflectiondirection is: " + hit2reflectionDirection); // shootRayBisShot = true; } } void shootRayC() { Debug.Log("shootRayC begins"); //________________________SHOOTC VARIABLES________________________________________ //set the gameobject's position to, "objectLocation" to allow for easy trans.pos Vector3 objectLocation = transform.localPosition; //Create a float to track the distance from where the object is to where it is going float dist3 = Vector3.Distance(objectLocation, hit3.point); Debug.Log("shootRayC variables loaded...functionality begins..."); //________________________SHOOTC FUNCTIONALITY________________________________________ //Cast a ray from hit2.point in the direction of hit2.point's reflection ray3 = new Ray(hit2.point, hit2reflectionDirection); Debug.Log("ray3 new ray is cast with: " + hit2.point); Debug.Log("as origin and direction as: " + hit2reflectionDirection); if (Physics.Raycast(hit2.point, hit2reflectionDirection, out hit3)) { Debug.Log("if(physics) is cast with: " + hit2.point); Debug.Log("as origin and direction as: " + hit2reflectionDirection); Debug.Log("shootRayC (physics) reads true, hit3 reads: " + hit3.point); //find the direction of the reflection of this ray hit3reflectionDirection = Vector3.Reflect(ray3.direction, hit3.normal); Debug.Log("hit3reflectiondirection origin is: " + ray3.direction); Debug.Log("as ray3.direction and normal as: " + hit3.normal); Debug.Log("hit3reflectiondirection is: " + hit3reflectionDirection); // shootRayCisShot = true; } } //________________________START() AND UPDATE()________________________________________ void Start() { // path = 0; Debug.Log("Start() is loaded and path is set to: " + path); } void Update() { Debug.Log("Update() begins"); //________________________UPDATE VARIABLES________________________________________ //set the gameobjects position to its form name to allow for easy trans.pos Vector3 objectLocation = transform.localPosition;//local or regular position? //Initiatlize and define speed, using step float speed = step * Time.deltaTime; //Create a float to track the distance from where the object is to where it is going float dist = Vector3.Distance(objectLocation, hit.point); float dist2 = Vector3.Distance(objectLocation, hit2.point); float dist3 = Vector3.Distance(objectLocation, hit3.point); //set a spacer for the ray position(which fires front the front[top] of the object) Vector3 raySpacer = new Vector3(0, 0, 1.1f); //lock the rotation transform.rotation = Quaternion.Euler(locPos, locPos, locPos); Debug.Log("tranform.rotation x, y, z is set to: " + locPos); Debug.Log("Update() variables loaded...functionality begins..."); //________________________UPDATE FUNCTIONALITY________________________________________ Debug.Log("Switch(path) begins: path set to: " + path); switch (path) { case 0: Debug.Log("C:0 begins..."); //while (path == 0) //{ fromObject = true; Debug.Log("C:0 running, fromobject set to: " + fromObject); if (shootRayAisShot == false) { Debug.Log("shootRayAisShot reads: " + shootRayAisShot); shootRayA(); } else { Debug.Log("shootRayAisShot reads: " + shootRayAisShot); } Debug.Log("C:0 shootRayA complete"); //Move towards hit.point transform.position = Vector3.MoveTowards(objectLocation, hit.point, speed); Debug.Log("C:0 trans.pos initiated, objectLocation is: " + objectLocation); Debug.Log("C:0 trans.pos initiated, hit.point is: " + hit.point); Debug.Log("dist is: " + dist); transform.LookAt(hit.point); Debug.Log("C:0 trans.lookat hit.point is: " + hit.point); Debug.DrawLine(fishLocation + raySpacer, hit.point, Color.magenta); Debug.Log("C:0 drawLine starts at: " + objectLocation + raySpacer); Debug.Log("C:0 drawLine ends at hit.point: " + hit.point); if (dist < 2) { Debug.Log("path(p1) is set to: " + path); Debug.Log("dist is: " + dist); path = 1; break; //} } break; case 1: //while (path == 1) //{ Debug.Log("C:1 begins..."); if (shootRayBisShot == false) { Debug.Log("shootRayBisShot reads: " + shootRayBisShot); shootRayB(); } else { Debug.Log("shootRayBisShot reads: " + shootRayBisShot); } Debug.Log("C:1 running, shootRayB complete"); //Move towards hit2.point transform.position = Vector3.MoveTowards(objectLocation, hit2.point, speed); Debug.Log("C:1 trans.pos initiated, current is: " + objectLocation); Debug.Log("C:1 trans.pos initiated, target is: " + hit2.point); transform.LookAt(hit2.point); Debug.Log("C:1 trans.lookat faces: " + hit2.point); Debug.DrawLine(objectLocation + raySpacer, hit2.point, Color.blue); Debug.Log("C:1 drawLine starts at: " + objectLocation + raySpacer); Debug.Log("C:1 drawLine ends at: " + hit2.point); if (dist2 < 2) { path = 2; Debug.Log("path(p2) is set to: " + path); Debug.Log("dist2 is: " + dist2); break; } //} break; case 2: //while (path == 2) //{ Debug.Log("C:2 begins..."); if (shootRayCisShot == false) { Debug.Log("shootRayCisShot reads: " + shootRayCisShot); shootRayC(); } else { Debug.Log("shootRayCisShot reads: " + shootRayCisShot); } Debug.Log("C:2 running, shootRayC complete"); //Move towards hit3.point transform.position = Vector3.MoveTowards(objectLocation, hit3.point, speed); Debug.Log("C:2 trans.pos initiated, current is: " + objectLocation); Debug.Log("C:2 trans.pos initiated, target is: " + hit3.point); transform.LookAt(hit3.point); Debug.Log("C:2 trans.lookat faces: " + hit3.point); Debug.DrawLine(objectLocation + raySpacer, hit3.point, Color.green); Debug.Log("C:2 drawLine starts at: " + objectLocation + raySpacer); Debug.Log("C:2 drawLine ends at: " + hit3.point); if (dist3 < 2) { path = 3; Debug.Log("path(p3) is set to: " + path); Debug.Log("dist3 is: " + dist3); break; } //} break; case 3: Debug.Log("C:3 begins..."); //while (path == 3) //{ fromObject = false; Debug.Log("C:3 running, fromObject set to: " + fromObject); if (shootRayAisShot == false) { Debug.Log("shootRayAisShot reads: " + shootRayAisShot); shootRayA(); } else { Debug.Log("shootRayAisShot reads: " + shootRayAisShot); } Debug.Log("C:3 shootRayA complete"); //Move towards hit.point transform.position = Vector3.MoveTowards(objectLocation, hit.point, speed); Debug.Log("C:3 trans.pos initiated, current is: " + objectLocation); Debug.Log("C:3 trans.pos initiated, target is: " + hit.point); transform.LookAt(hit.point); Debug.Log("C:3 trans.lookat faces: " + hit.point); Debug.DrawLine(objectLocation + raySpacer, hit.point, Color.red); Debug.Log("C:3 drawLine starts at: " + objectLocation + raySpacer); Debug.Log("C:3 drawLine ends at: " + hit.point); if (dist < 2) { Debug.Log("path(p1) is set to: " + path); Debug.Log("dist is: " + dist); path = 1; break; } //} break; } } }
*there is an object (the object this script is attached to)
*this object will cast a ray and mark the hit point
*define the reflection of this ray (direction, blah.normal)
*then a second ray will cast using the hit point of the first ray as its origin and the direction equal to the reflected direction.
*mark the second hit point(with a second raycasthit)
*repeat this a third time to allow for smoother transition(found that out the hard way) **WHAT I WANT TO HAPPEN:**
*the object will MoveTowards the first hit point
*if (objectDistanceFromFirstHitPoint < 2) { MoveTowards second hit point }
*if (objectDistanceFromSecondHitPoint < 2) { MoveTowards third hit point }
*recast first ray off of third ray and continue the pattern(second off of first, third off of second, first off of third, repeat)MY THOUGHTS:
*Hopefully you can tell I know how to code, this is more of a where does everything go kind of question.
*I am also aware that this is not the only way to do this (codewise)
*I did a huge debug to see if i could locate any problems. using UnityEngine; using System.Collections; public class proTest : MonoBehaviour { //create vector3s to hold the reflections public Vector3 hitreflectionDirection; public Vector3 hit2reflectionDirection; public Vector3 hit3reflectionDirection; //create two rays(one for current one for reflection) and raycasthit, a step to convert speed and a bool to cast a new ray Ray ray; Ray ray2; Ray ray3; RaycastHit hit; RaycastHit hit2; RaycastHit hit3; //Setup movement path as true/false booleans public float step = 10f; float locPos = 0; bool fromObject = true; //Allow for the creation of new instances of newray public rayToCast newray = new rayToCast(); //creates the random intergers for vector3 anglingNEEDS WORK! public class rayToCast { //create 3 random intergers to hold a random number between 1 and 360 and use them for random x, y, z coords public int randX = Random.Range(0, 360); public int randZ = Random.Range(0, 360); public int randY = Random.Range(0, 360); } // int path = 0; bool shootRayAisShot = false; bool shootRayBisShot = false; bool shootRayCisShot = false; // void shootRayA () { Debug.Log("shootRayA begins"); //________________________SHOOTA VARIABLES________________________________________ //set the gameobject's position to, "objectLocation" to allow for easy trans.pos Vector3 objectLocation = transform.localPosition; //set a spacer for the ray position(which fires front the front[top] of the capsule) Vector3 raySpacer = new Vector3(0, 0, 1.1f); //Create a vector Direction that takes in a new random vector3 using the random x, y, z coords Vector3 vecDir = new Vector3(newray.randX, newray.randY, newray.randZ); //create and define a random vector3 "rayAngler" to angle the ray, using vecDir to randomize Vector3 angledRayDirection = transform.up.y * vecDir; //Create a float to track the distance from where the fish is to where it is going //float dist = Vector3.Distance(fishLocation, hit.point); Debug.Log("shootRayA variables loaded...functionality begins..."); //________________________SHOOTA FUNCTIONALITY________________________________________ if (fromObject == true) { Debug.Log("fromfish reads: " + fromObject); //Cast a ray from object's location to random angle ray = new Ray(objectLocation + raySpacer, angledRayDirection); Debug.Log("ray new ray is cast with: " + objectLocation + raySpacer); Debug.Log("as origin and direction as: " + angledRayDirection); if (Physics.Raycast(objectLocation + raySpacer, angledRayDirection, out hit)) { Debug.Log("shootRayA if(physics) reads true, hit reads: " + hit.point); Debug.Log("if(physics) is cast with: " + objectLocation + raySpacer); Debug.Log("as origin and direction as: " + angledRayDirection); //find the direction of the reflection of this ray hitreflectionDirection = Vector3.Reflect(ray.direction, hit.normal); Debug.Log("hitreflectiondirection origin is: " + ray.direction); Debug.Log("as ray.direction and normal as: " + hit.normal); Debug.Log("hitreflectiondirection is: " + hitreflectionDirection); // shootRayAisShot = true; } } else { Debug.Log("fromObject else loaded with fromObject reading: " + fromObject); //Cast a ray from hit3.point in the direction of hit3.point's reflection ray = new Ray(hit3.point, hit3reflectionDirection); Debug.Log("fromObject else ray cast with: " + hit3.point); Debug.Log("as origin and direction as: " + hit3reflectionDirection); if (Physics.Raycast(hit3.point, hit3reflectionDirection, out hit)) { Debug.Log("shootRayA else(physics) reads true, hit reads: " + hit.point); Debug.Log("else(physics) is cast with: " + hit3.point); Debug.Log("as origin and direction as: " + hit3reflectionDirection); //find the direction of the reflection of this ray hitreflectionDirection = Vector3.Reflect(ray.direction, hit.normal); Debug.Log("hitreflectiondirection origin is: " + ray.direction); Debug.Log("as ray.direction and normal as: " + hit.normal); Debug.Log("hitreflectiondirection is: " + hitreflectionDirection); // shootRayAisShot = true; } } } void shootRayB() { Debug.Log("shootRayB begins"); //________________________SHOOTB VARIABLES________________________________________ //set the gameobject's position to, "objectLocation" to allow for easy trans.pos Vector3 objectLocation = transform.localPosition; //Create a float to track the distance from where the objext is to where it is going float dist2 = Vector3.Distance(objectLocation, hit2.point); Debug.Log("shootRayB variables loaded...functionality begins..."); //________________________SHOOTB FUNCTIONALITY________________________________________ //Cast a ray from hit.point in the direction of hit.point's reflection ray2 = new Ray(hit.point, hitreflectionDirection); Debug.Log("ray2 new ray is cast with: " + hit.point); Debug.Log("as origin and direction as: " + hitreflectionDirection); if (Physics.Raycast(hit.point, hitreflectionDirection, out hit2)) { Debug.Log("if(physics) is cast with: " + hit.point); Debug.Log("as origin and direction as: " + hitreflectionDirection); Debug.Log("shootRayB (physics) reads true, hit2 reads: " + hit2.point); //find the direction of the reflection of this ray hit2reflectionDirection = Vector3.Reflect(ray2.direction, hit2.normal); Debug.Log("hit2reflectiondirection origin is: " + ray2.direction); Debug.Log("as ray2.direction and normal as: " + hit2.normal); Debug.Log("hit2reflectiondirection is: " + hit2reflectionDirection); // shootRayBisShot = true; } } void shootRayC() { Debug.Log("shootRayC begins"); //________________________SHOOTC VARIABLES________________________________________ //set the gameobject's position to, "objectLocation" to allow for easy trans.pos Vector3 objectLocation = transform.localPosition; //Create a float to track the distance from where the object is to where it is going float dist3 = Vector3.Distance(objectLocation, hit3.point); Debug.Log("shootRayC variables loaded...functionality begins..."); //________________________SHOOTC FUNCTIONALITY________________________________________ //Cast a ray from hit2.point in the direction of hit2.point's reflection ray3 = new Ray(hit2.point, hit2reflectionDirection); Debug.Log("ray3 new ray is cast with: " + hit2.point); Debug.Log("as origin and direction as: " + hit2reflectionDirection); if (Physics.Raycast(hit2.point, hit2reflectionDirection, out hit3)) { Debug.Log("if(physics) is cast with: " + hit2.point); Debug.Log("as origin and direction as: " + hit2reflectionDirection); Debug.Log("shootRayC (physics) reads true, hit3 reads: " + hit3.point); //find the direction of the reflection of this ray hit3reflectionDirection = Vector3.Reflect(ray3.direction, hit3.normal); Debug.Log("hit3reflectiondirection origin is: " + ray3.direction); Debug.Log("as ray3.direction and normal as: " + hit3.normal); Debug.Log("hit3reflectiondirection is: " + hit3reflectionDirection); // shootRayCisShot = true; } } //________________________START() AND UPDATE()________________________________________ void Start() { // path = 0; Debug.Log("Start() is loaded and path is set to: " + path); } void Update() { Debug.Log("Update() begins"); //________________________UPDATE VARIABLES________________________________________ //set the gameobjects position to its form name to allow for easy trans.pos Vector3 objectLocation = transform.localPosition;//local or regular position? //Initiatlize and define speed, using step float speed = step * Time.deltaTime; //Create a float to track the distance from where the object is to where it is going float dist = Vector3.Distance(objectLocation, hit.point); float dist2 = Vector3.Distance(objectLocation, hit2.point); float dist3 = Vector3.Distance(objectLocation, hit3.point); //set a spacer for the ray position(which fires front the front[top] of the object) Vector3 raySpacer = new Vector3(0, 0, 1.1f); //lock the rotation transform.rotation = Quaternion.Euler(locPos, locPos, locPos); Debug.Log("tranform.rotation x, y, z is set to: " + locPos); Debug.Log("Update() variables loaded...functionality begins..."); //________________________UPDATE FUNCTIONALITY________________________________________ Debug.Log("Switch(path) begins: path set to: " + path); switch (path) { case 0: Debug.Log("C:0 begins..."); //while (path == 0) //{ fromObject = true; Debug.Log("C:0 running, fromobject set to: " + fromObject); if (shootRayAisShot == false) { Debug.Log("shootRayAisShot reads: " + shootRayAisShot); shootRayA(); } else { Debug.Log("shootRayAisShot reads: " + shootRayAisShot); } Debug.Log("C:0 shootRayA complete"); //Move towards hit.point transform.position = Vector3.MoveTowards(objectLocation, hit.point, speed); Debug.Log("C:0 trans.pos initiated, objectLocation is: " + objectLocation); Debug.Log("C:0 trans.pos initiated, hit.point is: " + hit.point); Debug.Log("dist is: " + dist); transform.LookAt(hit.point); Debug.Log("C:0 trans.lookat hit.point is: " + hit.point); Debug.DrawLine(fishLocation + raySpacer, hit.point, Color.magenta); Debug.Log("C:0 drawLine starts at: " + objectLocation + raySpacer); Debug.Log("C:0 drawLine ends at hit.point: " + hit.point); if (dist < 2) { Debug.Log("path(p1) is set to: " + path); Debug.Log("dist is: " + dist); path = 1; break; //} } break; case 1: //while (path == 1) //{ Debug.Log("C:1 begins..."); if (shootRayBisShot == false) { Debug.Log("shootRayBisShot reads: " + shootRayBisShot); shootRayB(); } else { Debug.Log("shootRayBisShot reads: " + shootRayBisShot); } Debug.Log("C:1 running, shootRayB complete"); //Move towards hit2.point transform.position = Vector3.MoveTowards(objectLocation, hit2.point, speed); Debug.Log("C:1 trans.pos initiated, current is: " + objectLocation); Debug.Log("C:1 trans.pos initiated, target is: " + hit2.point); transform.LookAt(hit2.point); Debug.Log("C:1 trans.lookat faces: " + hit2.point); Debug.DrawLine(objectLocation + raySpacer, hit2.point, Color.blue); Debug.Log("C:1 drawLine starts at: " + objectLocation + raySpacer); Debug.Log("C:1 drawLine ends at: " + hit2.point); if (dist2 < 2) { path = 2; Debug.Log("path(p2) is set to: " + path); Debug.Log("dist2 is: " + dist2); break; } //} break; case 2: //while (path == 2) //{ Debug.Log("C:2 begins..."); if (shootRayCisShot == false) { Debug.Log("shootRayCisShot reads: " + shootRayCisShot); shootRayC(); } else { Debug.Log("shootRayCisShot reads: " + shootRayCisShot); } Debug.Log("C:2 running, shootRayC complete"); //Move towards hit3.point transform.position = Vector3.MoveTowards(objectLocation, hit3.point, speed); Debug.Log("C:2 trans.pos initiated, current is: " + objectLocation); Debug.Log("C:2 trans.pos initiated, target is: " + hit3.point); transform.LookAt(hit3.point); Debug.Log("C:2 trans.lookat faces: " + hit3.point); Debug.DrawLine(objectLocation + raySpacer, hit3.point, Color.green); Debug.Log("C:2 drawLine starts at: " + objectLocation + raySpacer); Debug.Log("C:2 drawLine ends at: " + hit3.point); if (dist3 < 2) { path = 3; Debug.Log("path(p3) is set to: " + path); Debug.Log("dist3 is: " + dist3); break; } //} break; case 3: Debug.Log("C:3 begins..."); //while (path == 3) //{ fromObject = false; Debug.Log("C:3 running, fromObject set to: " + fromObject); if (shootRayAisShot == false) { Debug.Log("shootRayAisShot reads: " + shootRayAisShot); shootRayA(); } else { Debug.Log("shootRayAisShot reads: " + shootRayAisShot); } Debug.Log("C:3 shootRayA complete"); //Move towards hit.point transform.position = Vector3.MoveTowards(objectLocation, hit.point, speed); Debug.Log("C:3 trans.pos initiated, current is: " + objectLocation); Debug.Log("C:3 trans.pos initiated, target is: " + hit.point); transform.LookAt(hit.point); Debug.Log("C:3 trans.lookat faces: " + hit.point); Debug.DrawLine(objectLocation + raySpacer, hit.point, Color.red); Debug.Log("C:3 drawLine starts at: " + objectLocation + raySpacer); Debug.Log("C:3 drawLine ends at: " + hit.point); if (dist < 2) { Debug.Log("path(p1) is set to: " + path); Debug.Log("dist is: " + dist); path = 1; break; } //} break; } } }