MY AIM
My aim is to click at a chosen point on the map using a raycast (done) and a gameobject (robot/tank) will move to the area you have clicked.
The game in trying to create is a first-person RTS (Real-time-stratagy) where the player can command his army using a first-person camera pointing and clicking where he wants his units (tanks/robots) to move to on the map.
MAIN QUESTION
How do i implement the transform/translate/slerp etc in to the script. I tryed many solutions, looked on youtube, unity answers forums but i am not given the correct result and i do not understand how it works.
Oh and also, do i need a Character controller/Motor controller to move the vehicle (Tank/Robot)
MOVEMENT SCRIPT (JS)
if( Hit.collider.gameObject){
bot.transform.Translate(Vector3.forward * speed * Time.deltaTime); //The final result of the script
bot.transform.Translate(-Vector3.forward * speed * Time.deltaTime);
bot.transform.Rotate(Vector3.up, -rotation * Time.deltaTime);
bot.transform.Rotate(Vector3.up, rotation * Time.deltaTime);
Debug.LogWarning("Potatoes!"); //Success, the script works!
MY CURRENT SCRIPT (JS)
var bot : Transform; //The robot/gameobject that must follow the raycast
var Range : float; // Range of the raycast
var mesh : GameObject; //Cammea the raycast beam comes from
var Hit : RaycastHit; //Impact/cordinates of the raycast the robot must goto
var speed : float = 0.6; //Speed of the robot
var rotation : float = 0.6; //rotation 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.Translate(Vector3.forward * speed * Time.deltaTime); //The final result of the script
bot.transform.Translate(-Vector3.forward * speed * Time.deltaTime);
bot.transform.Rotate(Vector3.up, -rotation * Time.deltaTime);
bot.transform.Rotate(Vector3.up, rotation * Time.deltaTime);
Debug.LogWarning("Potatoes!"); //Success, the script works!
}
}
}
BONUS QUESTION
For the raycast i noticed there is something call a “screenPointToRay”. Can i use that in place of my current raycast section?
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)){
READ BEFORE POSTING
- If you are going to post any links please explain it with your own words, the explanation in the link may not be explained well enough for me to understand.
- Feel free to modify the script i have provied, although i would be very happy if you would explain a few things.
- Currently im in college so im no expert in coding, i am currently learning the theory.
- NO GOOGLE IT’S as i already have. We must move forward, not back.

Appologies if ive been abit rude! ![]()
FINALY
Thank you for your time!