- Home /
Duplicate Question
How to get a ai to drive to a raycast
I am making a script for a ai robot to go to a 'hit raycast'. The script for that is done, i just cant figure out the movement.
Yes i have looked at the character controller script and it dosnt make sence to me.
I want it to move like a tank, go forwards, backwards, turn left, turn right etc
I think its something along these lines.
var bot : GameObject; //The robot that must follow the raycast
var speed : float = 0.6; //Speed of the robot
bot.transform.position, speed * Time.deltaTime =(Hit.point);
This is my script at the moment...
var bot : GameObject; //The robot that must follow the raycast
var Range : float; // Range of the raycast
var mesh : GameObject; //Cammea the raycast comes from
var Hit : RaycastHit; //Impact of the raycast the robot must follow
var speed : float = 0.6; //Speed of the robot
//References of how i learnt about raycasting
//http://answers.unity3d.com/questions/15761/click-on-terrain-and-record-vector3-location-i-cli.html
//http://www.youtube.com/watch?v=cZsG4dfCUec
//http://www.youtube.com/watch?v=-F_w3RDRbN4
function Update () {
if(Input.GetMouseButtonUp(1))
var Directionofline : Vector3 = mesh.transform.TransformDirection(Vector3.forward);
Debug.DrawRay( mesh.transform.position, Directionofline * Range, Color.yellow); //Raycast in visual
if(Physics.Raycast( mesh.transform.position, Directionofline, Hit, Range)){
if( Hit.collider.gameObject){
bot.transform.position, speed * Time.deltaTime =(Hit.point); //The final result of the script
Debug.LogWarning("Potatoes!"); //Success the script works!
}
}
}
Duplicate Question : http://answers.unity3d.com/questions/412440/how-to-get-a-ai-to-drive-to-a-raycast.html
Please Delete this Question.
Please be patient if your question/reply doesn't show straight away.
As a new user, your posts and questions are held in a moderator que until it is approved and then it is displayed. When your karma rises, you'll be able to post questions, comments and answers without waiting for someone to approve it =]
Follow this Question
Related Questions
How to get a ai to drive to a raycast 0 Answers
Set Quaternion to another Quaternion, but oriented along 1 Answer
Following Terrain Height? 2 Answers
Moving Character Along Round Tunnel Walls 0 Answers
I need help with dragging objects 1 Answer