So I have these small panels (0.1 scale, not sure if I should be doing that, or just making the map bigger) I have a larger box collider on the panels, and they are a rigidbody. My code looks like this (Layer 8 is my flashlight, which I don’t want the panel to care about, otherwise it should turn left before it hits the object, which it isn’t doing)
void Start()
{
ray = new Ray(transform.position, transform.forward);
}
void Update()
{
LayerMask layerMask = 1 << 8;
if (Physics.Raycast(ray,out hit,50f,layerMask))
{
transform.Rotate(Vector3.up, -90 * 5 * Time.smoothDeltaTime);
}
else
{
if (UpDown)
transform.Translate(0, 0, 2 * Time.deltaTime, Space.Self);
else
transform.Translate(0, 0, 2 * Time.deltaTime, Space.Self);
}
}
EDIT:
When I use this code, I do hit the wall (though I spin in circles as walls are all around) whenever I add a distance, the plane just walks right up to the wall.
if (Physics.Raycast(ray,out hit))
{
Debug.Log(hit.distance.ToString() + " " + hit.collider.gameObject.name);
transform.Rotate(Vector3.up, -90 * 5 * Time.smoothDeltaTime);
}
else
{
if (UpDown)
transform.Translate(0, 0, 2 * Time.deltaTime, Space.Self);
else
transform.Translate(0, 0, 2 * Time.deltaTime, Space.Self);
}