My first Unity project[Car]

[SKIP THE BLABLA AND GIVE THE GAME A TRY[/B][/URL]
Hello people, let me introduce myself : I’m Sohaib, a 17 years old computers amateur, i’ve a basic knowledge in C#, i can handle things pretty well in photoshop.
I’ve heared about Unity and it’s been always my dream to create and manage games, so i’ve decided that my first project should be a free-to-drive-car game.
Details: there isn’t much details about it, it’s just a car that you drive all over the terrain.
I brought the terrain textures the car from the Assets Store, i edited the car’s color and added that cute logo.
the movement basics are simple: Z move forward, S backward, if you’re already moving, you can turn left or right.
First, i had issues because the vehicle was falling throught the terrain, even if it’s a rigidbody, i added a box collision to it(the only one that worked) it solved the problem but i’m still feeling it’s the wrong way to do it.
To be honest with you, physics are pretty messed up, and my first goal from making this thread is improving my project and knowing where should i correctly start from.
This is the C# class that’s moving my car:
```php
**using UnityEngine;
using System.Collections;

public class CarDriver : MonoBehaviour {
public float forwardSpeed = 40.0f;
public float backwardSpeed = 20.0f;
public float rotateSpeed = 80.0f;

// Use this for initialization
void Start () {

}

// Update is called once per frame
void Update () {
if (Input.GetKey(KeyCode.Z))
	{
		transform.position -= transform.forward * forwardSpeed * Time.deltaTime;
	}
if (Input.GetKey(KeyCode.S))
	{
		transform.position += transform.forward * backwardSpeed * Time.deltaTime;
	}

if (Input.GetKey(KeyCode.Z))
{

if (Input.GetKey(KeyCode.Q))
	{
		transform.Rotate( 0.0f, -rotateSpeed * Time.deltaTime, 0.0f);
	}
if (Input.GetKey(KeyCode.D))
	{
		transform.Rotate( 0.0f, rotateSpeed * Time.deltaTime, 0.0f);
	}
	}

else if (Input.GetKey(KeyCode.S))
{
if (Input.GetKey(KeyCode.Q))
{
transform.Rotate( 0.0f, rotateSpeed * Time.deltaTime, 0.0f);
}
if (Input.GetKey(KeyCode.D))
{
transform.Rotate( 0.0f, -rotateSpeed * Time.deltaTime, 0.0f);
}
}
}
}**
```
and these are some screenshots:



Thank you for checking my thread, i hope that who know better than me enlighten me with his knowledge.
Any criticisms is always welcome](http://neoxads.com/sohaib/Car.html)

Could you post a webplayer for us to drive it?

Project update #1

I added a re-spawn script if you fall from the terrain, and also a “SPACE” key for it
Realized that the car is too light and that’s why it flies all over the terrain and falls slowly
Realized that the car weight problem is because everything is big in the project and newton says that all objects fall with the same speed no matter how heavy they were.

Wanna give it a try? here’s the link
CarProject

what are the controls? i can only make the car go backwards!

Yes, what are the controls? Also, why not use wheel colliders?
I’d recommend using WASD or arrowkeys(Hotizontal/Vertical Axis) for the controls.

His setup must be AZERTY. But I couldn’t control the car at all.

If you look at the code, it uses an odd ZSQD format. Which, in turn, made it undrivable.

Wait- ZSQD? My brain hurts.

I sincerely apologize for the keys, yes i’ve AZERTY keyboard, and i completely forgot about changing the keys for WASD, now it’s fixed.

a apologize again.

Link: http://neoxads.com/sohaib/Car.html

Set up a SmoothFollow script on the camera(it’s in the default assets of scripts). Set it to follow the vehicle. Also, show us a pic of your rigidbody settings. The car, as you said, is falling down pretty slow. We can provide assistance in trying to solve it.

Biggest stand out, other than gravity speed is that you can drive and steer while in the air! I think a raycast from the back two tyres to toggle forwards/backwards, and a raycast from the front two tyres to toggle left/right should fix this.

This is the “car” proprieties as you asked me

i tried to add a wheel collider to each tire, everything got screwed

i also added the smooth-follow script

@oysterCAKE i didn’t really understand you, because my driver script is very basic, there’s nothing mechanic, i’m just messing with coords through keys, is there really a way to make the wheels turn and add a friction force like in real life?

I’ll update the game in a few minutes

Possibly try to change the Interpolate to the highest setting. Also, remove the animation(Though it wouldn’t help here, it’s not needed).

There is an excellent car tutorial(with wheel colliders), provided here:
http://www.gotow.net/andrew/blog/?page_id=78

Awesome, I hit a hill and my car went flying into the Sky! Then it crashed upside down!

I was looking for something like this. Thanks!

Here’s a quick hint for you.

It seems as though you are applying force to the car to make it move. You shouldn’t do this. Instead make each individual wheel have its own collider and rotate each through the physics engine. This way you will get a lot better acting car instead of a helicopter-ish car thing.

I removed that stupid box collider thing, then i added new colliders that are more organized and a lot more accurate.

  • 4 Wheel Colliders
  • One big box collider for the body
  • One smaller box collider for the updder body

This is a small screennie about it

I also multiplied the gravity by 10, because the terrain is x10 bigger than the real world, now it’s a lot more realistic

my next task is making the weels turn and make the friction between the terrain and the wheels is what makes the car move, i still didn’t figure out the way to it, but working on it

Thank you guys for your support:wink:

Make everything normal size. That is best. :slight_smile: It’ll be much nicer. Then send us a webplayer to try!

When I attempt to add the C# script that you provided(I named the script ‘car’) to an object with the name car it doesn’t allow me, help

Change your class name inside the class and save it then add to that object