- Home /
Question by
john-essy · Nov 24, 2011 at 06:45 PM ·
airaycasting
Please Someone help with my Raycasting Rotate
Hi there and thanks for looking. The problem i am having is this. When my AI touches something it is meant to rotate then start moving again but it doesn't i have changed this code so many times i have forgot how i got it working partially. Please someone help as it is getting really annoying. All i want is for him to go towards the player when he is not hitting anything, Then when he is hitting something stop and stop looking at the player then rotate either left or right here is my code well broken code
var target;
var hit : RaycastHit;
var rayLength : float = 15.0f;
var speed : float;
var robotController : CharacterController;
var rotateAmount : float;
var moveDirection : Vector3 = Vector3.left;
function Start()
{
target = GameObject.Find("MadDoc").GetComponent(Transform);
robotController = GetComponent("CharacterController");
}
function Update ()
{
var dirForward = transform.TransformDirection(Vector3.forward);
Debug.DrawRay(transform.position, dirForward * rayLength, Color.black);
if(!Physics.Raycast(transform.position, dirForward , hit , rayLength))
{
robotController.SimpleMove(dirForward * speed * Time.deltaTime);
animation.CrossFade("walk");
transform.LookAt(target);
}
else
{
Debug.Log("We are hitting! ");
robotController.Move(moveDirection * Time.deltaTime);
}
}
Comment
Your answer
Follow this Question
Related Questions
Raycast to detect how high blocks are infront of object 1 Answer
Another Raycast Issue. 0 Answers
raycast cooler 2 Answers
How Can I make an AI change animation once looked at using Raycasting. 2 Answers
Raycasting Help 2 Answers