• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by NinjaRubberBand · Mar 25, 2013 at 01:14 AM · car

using your own car - car tutorial

I made my own car in 3ds max, and imported it to my unity project. So, i want it to drive, so i dragged all the scripts the car tutorial car have, and added a ridgidbody. but it still wont drive? What do i do wrong?

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image NinjaRubberBand · Mar 25, 2013 at 04:50 PM 0
Share

Plz its important, :)

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by NinjaRubberBand · Mar 25, 2013 at 07:25 PM

Hmm.. I tried Javascript and C# but it dosen't work.. it says Assets/CarMotor.js(1,6): UCE0001: ';' expected. Insert a semicolon at the end.

Comment
Add comment · Show 5 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image fafase · Mar 26, 2013 at 07:41 AM 0
Share

It is a cs script and one } was out of the code layout.

avatar image NinjaRubberBand · Mar 26, 2013 at 05:09 PM 0
Share

Have you tested it out yourself? I just doesen't work..

avatar image fafase · Mar 27, 2013 at 08:43 AM 0
Share

Yes I did. But actually there is still one issue on my answer, two comas are missing in the parameters of Clamp.

avatar image NinjaRubberBand · Mar 27, 2013 at 09:21 AM 0
Share

What version of unity are you using?

avatar image fafase · Mar 27, 2013 at 12:43 PM 0
Share

The grey one. I just tried it right now and it does work. Just use another script, I can't help you more.

avatar image
0

Answer by fafase · Mar 25, 2013 at 05:17 PM

This below is the most basic car script that can be. You need to add four wheel colliders to your car and position them at the four wheel with appropriate dimension. Then drag and drop into the corresponding wheel collider variables of your script.

Give some mass to the rigidbody, some values to the steer, motor and brake and roll on. You may have to tweak your center of mass until your car stops flipping. Also, make usre the wheel collider friction values are set to a low value like 0.02/0.03 or your car will flip as soon as your steer.

 using UnityEngine;
 using System.Collections;

 [RequireComponent(typeof(Rigidbody))]
 public class MovementCar : MonoBehaviour {

 public WheelCollider frontLeft;
 public WheelCollider frontRight;
 public WheelCollider backLeft;
 public WheelCollider backRight;
 Rigidbody _rigidbody;
 Transform _transform;
 Vector3 _currentRotation;
 public float steer_max = 20f,motor_max=10f,brake_max=100;
 float steer = 0f,motor=0f,brake=0f;
 void Awake(){
     _rigidbody = rigidbody;
     _transform = transform;
     _currentRotation = new Vector3 (transform.localEulerAngles.x,
     transform.localEulerAngles.y, transform.localEulerAngles.z);
 }
 
 void Start () {
     _rigidbody.centerOfMass = new Vector3(0.0f,-0.95f,0.0f);
 }
 
 void FixedUpdate () {
     steer = Input.GetAxis("Horizontal");
     motor = Mathf.Clamp(Input.GetAxis("Vertical"),0,1);
     brake = Mathf.Clamp(Input.GetAxis("Vertical"),-1,0);

             frontLeft.motorTorque = motor_max*motor;
     frontRight.motorTorque = motor_max*motor;
     frontLeft.brakeTorque = brake_max * brake;
     frontRight.brakeTorque = brake_max*brake;
     frontLeft.steerAngle = steer_max*steer;
     frontRight.steerAngle = steer_max *steer;

 } 
 void LateUpdate()
 {
     if (steer == 0){
         float y = _currentRotation.y;
         _transform.localEulerAngles = new Vector3 (transform.localEulerAngles.x, y, transform.localEulerAngles.z);
     }else
     _currentRotation.y = transform.localEulerAngles.y;
 }
 
 void OnGUI(){
     GUI.Box(new Rect(50,50,200,50),(CarVelocity ()).ToString("0")+"km/h");
 }
 float CarVelocity(){    
     return 2f * Mathf.PI*backLeft.radius *backLeft.rpm*60f/1000f;
 }
 }
Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

11 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

script car 0 Answers

Car enter and exit script not working 1 Answer

How to check if car entered garage... then if true, do a specified function ? -1 Answers

Front wheel rotates in play mode 1 Answer

Laggy Camera 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges