Question by
tylerhollows · Nov 24, 2016 at 06:38 PM ·
unity 5physicsraycastphysics.raycastfpscontroller
How to make a Physics.Raycast detect a FPSController?
I am trying to make an AI that spins around until it sees the player, but it can only see walls and other objects, but completely ignores the FPSController. I tried adding a cube to the controller, and the FPSController is tagged as player, but it won't see it. Here is what I have:
using UnityEngine;
using System.Collections;
public class PersonAI : MonoBehaviour
{
public RaycastHit hit;
public float fpsTargetDistance = 10;
public float enemyLookDistance = 10;
public Transform fpsTarget;
public float ran;
void Update()
{
ran = Random.Range(-5, 5);
transform.Rotate(0,ran,0, Space.World);
fpsTargetDistance = Vector3.Distance(fpsTarget.position, transform.position);
if (Physics.Raycast(transform.position, transform.TransformDirection(Vector3.forward), out hit))
{
Debug.Log (hit.transform.tag);
if(hit.transform.tag == "Player")
{
SeenPlayer();
}
}
}
void SeenPlayer()
{
MoneyDisplay.money-= 10;
}
}
Comment