- Home /
How can i make a vehicle move where I touch on ground?
Hi I am looking for a way that make it possible to move a vehicle to move to where I touch or click by mouse I know how to do this with character using Ray Cast I don't know and so on but Vehicle is different...I don't want it to move like a walking car for example hah hah.....I want it to move where i touch or click and it uses torque wheel collider and steering and braking to reach that vector3 i have placed by mouse click i remember it was available for a sample scene of assets package it was sky-car i remember where i clicked the car went there.....please give me script or a link or whatever....I will extremely be grateful
like this
then
Answer by Luucccc · Mar 20, 2018 at 06:57 PM
By using Physics.Raycast down to your mouse position, and outputting that data to a RaycastHit. You can use https://docs.unity3d.com/ScriptReference/Transform.LookAt.html to have your unit look towards your hit position. Then for smooth movement towards the target position you could use https://docs.unity3d.com/ScriptReference/Vector3.Lerp.html to move towards your target at a constant speed. Also, when using Lerp read the documentation well as the last parameter is taken as a value between 0 and 1 (A fraction representing the current distance and the distance left to travel). Hope this helps!