Hello!
I’d like to move a Car (I downloaded for free in the assets) in a very simple 3D Map (Terrain) witch has some “hills” … It’s not flat!
I can’t achieve this (simple?) task! ![]()
In the awake I set two random floats for the location point on the map (x and z in the map). Of course my car should not fly! So the Y must follow the terrain inclinations!
I tried with Character Controller but I don’t know how to let my car stay on the floor (I watched “gravity” tutorial but car seem to “sink” with wheels into the terrain grass.
Now I am trying with Rigidbody and Gravity, but Car just stands on his back bouncing around!
(wheelie)
I used two capsule colliders for the read and front wheels and another capsule for the trigger on the center of my car.
In the awake I have:
private void Awake()
{
speed = 1.5f;
float x = Random.Range(5f, 90f);
float z = Random.Range(5f, 90f);
float y = transform.position.y;
dest = new Vector3(x,y,z);
Debug.Log("dest: " + dest + "io sono a: " + transform.position);
arrived = false;
}
With a FixedUpdate I call this:
private void VaiVersoPlayer()
{
myPosition = transform.position;
if (Vector3.Distance(myPosition, dest) > 2.5f && isGrounded)
{
transform.position = Vector3.MoveTowards(transform.position, dest, Time.deltaTime * speed);
transform.LookAt(dest, Vector3.back);
if (transform.rotation.eulerAngles.z != 0f)
{
transform.rotation = Quaternion.Euler(transform.rotation.eulerAngles.x, transform.rotation.eulerAngles.y, transform.rotation.z);
}
}
}
do you know how to make this 3D car climb up and down hills untill reach that random point?
I was thinking about “waypoints” but … I have to try it tomorrow!
Thanks for you helping!