Hello,
What I’m trying to do is make a sort of Pathing algorithm with using forward/diagonal rays.
Right now my code is : (OLD CODE, working code below)
void managePathingAndMovement()
{
forwardRayCast();
if (!moveTowardsEnd)
{
translate();
}
}
private Vector3 moveDirection; //No point in using atm
void forwardRayCast()
{
Ray fowRay = new Ray(_rayCastObject.position, Vector3.forward);
RaycastHit fowHit;
if (Physics.Raycast(fowRay, out fowHit, Mathf.Infinity)) //Change Mathf.Inf
{
transform.eulerAngles = new Vector3(0, transform.eulerAngles.y + 1, 0); //Sets the y rotation to +1 every frame while stil Raycasting
}
else
{
moveTowardsEnd = true;
}
}
void translate()
{
transform.Translate(Vector3.forward * 10 * Time.deltaTime);
}
I can’t actually rotate the transform itself, and the weird thing is that my Vector3.forward changes as my character rotates, but the Raycast seems to be working independently.
Also, I’ve tried shooting the ray from both the transform itself and the child object. Both times it’s just pointing dead ahead. How would I go about fixing this? – Fixed with multiplication
private Vector3 moveDirection;
void forwardRayCast()
{
moveTowardsEnd = false;
Vector3 forward = Quaternion.Euler(_rayCastObject.localEulerAngles) * Vector3.forward; //Rotates toward the localRotation by using eulerAngles
Ray fowRay = new Ray(_rayCastObject.position,forward );
RaycastHit fowHit;
Debug.DrawRay(_rayCastObject.position, forward);
if (Physics.Raycast(fowRay, out fowHit, Mathf.Infinity)) //Change Mathf.Inf
{
transform.eulerAngles = new Vector3(0, transform.eulerAngles.y + 1, 0); //Sets the y rotation to +1 every frame while stil Raycasting
_rayCastObject.localEulerAngles = transform.localEulerAngles;
}
else
{
//moveTowardsEnd = true;
}
}