Hi All,
I’m very new to Unity and am having trouble with ray casting. Basically I have a cube that can move around the world (with a neural network behind) using:
transform.Rotate(0, output[0] * rotation, 0, Space.World); //controls the turning
transform.position += this.transform.right * output[1] * speed; //controls the movement
I am able to fire out some rays in front of the cube using this (‘i’ being a loop of 0-4):
Vector3 newVector = Quaternion.AngleAxis(i * 45 - 90, new Vector3(0, 1, 0)) * transform.right; //calculates angle of raycast
RaycastHit hit;
Ray Ray = new Ray(transform.position, newVector);
if (Physics.Raycast(Ray, out hit, 10, raycastMask)) { ...
This is fine for layers that appear directly in front of the cube (I believe therefore x = 0) however I want to angle these ray casts down a bit too (as if the cube were looking at the ground in front of itself)?
How could I go about this, would it be something like Quaternion.LookRotation?
Many Thanks in advance for your help