- Home /
vehicle moveing on the terrain
I just looked for a simple vehcle script that can make a vehicle move around the terrain and being able to climb montians (not spoting and avoiding obsticle on the way). All I found is the same problem but when the vehcle is controlled buy the player, and not when the vehcle is controlled only buy the computer.
So my problem is this: I made a simple vehicle which all it do is following me. I made a simple script so it will be able to find me after spawning, rotate and move forward. When I using this script the vehicle is flying to my direction and not stick to the ground like it should, so I added a rigidbody to it and now it falling trough the ground, even if I adding a mesh collider to it.
How I making the vehicle stick to the groud when it folloing me and not fly or falling trough the ground?
This is my script:
var speed : double = 50;
var damping = 3;
var target;
var targetDistance : double;
var attackRange = 60;
function Start ()
{
target = GameObject.FindWithTag("Player").transform;
}
function Update ()
{
targetDistance = Vector3.Distance(target.position, transform.position);
//movement
if (targetDistance > attackRange)
{
print ("is active");
var rotation = Quaternion.LookRotation(target.position - transform.position);
transform.rotation = Quaternion.Slerp(transform.rotation, rotation, Time.deltaTime * damping);
transform.Translate(Vector3.forward * speed * Time.deltaTime);
}
}
Sorry for poor english.
Your answer
Follow this Question
Related Questions
How to attach a terrain to an object? 1 Answer
Vehicle Movement Script Not Moving Forwards 1 Answer
2D movement colliding problem 1 Answer
Terrain Slope Bouncing 1 Answer
Hide end of world 3 Answers