- Home /
raycasts only working with IsTrigger colliders?
My code works fine except the raycasts only work with colliders that have IsTrigger set to true.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class BotControllerRays : MonoBehaviour
{
public float mockTurnSlider = 0;
public float mockOarSlider = 0;
private float tempTimer = 0;
// Start is called before the first frame update
void Start()
{
mockTurnSlider = 0;
mockOarSlider = 50;
}
void FixedUpdate()
{
tempTimer++;
if (tempTimer == 50)
{
Rays();
tempTimer = 0;
}
}
void Rays()
{
print("rays");
for (int i = -6; i <= 6; i=i+1)
{
transform.localEulerAngles = new Vector3(0, i*30, 0);
RaycastHit hit;
if (Physics.Raycast(transform.position, transform.forward, out hit,3000))
{
Debug.Log(hit.collider.name);
print(transform.localEulerAngles.y +" | "+ hit.distance);
if (hit.collider.gameObject.CompareTag("Player")|| hit.collider.gameObject.CompareTag("Ally"))
{
mockTurnSlider = (i / 6) / hit.distance*1000;
print(mockTurnSlider);
//print("found Player");
if (hit.distance < 250 && transform.localEulerAngles.y == 0)
{
mockOarSlider = 100;
}
}
}
}
}
}
Comment