Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • 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 ghhwer · Oct 26, 2012 at 12:09 PM · c#gamecarcontrol

Car Script error C#

Hello guys I was trying to make a script for my car in my game but every time my car rotates it goes sideways like if the z axis didn't rotate with the object

the script goes like this:

 using UnityEngine;
 using System.Collections;
 
 public class CarControl : MonoBehaviour {
     
     public bool Driveble = false;
     public bool isTouching = true;
     public float MaxAcelerationForwards = 0.0f;
     public float MaxAcelerationBackwards = 0.0f;
     private float currentacelerationF = 0.0f;
     private float currentacelerationB = 0.0f;
            
            private float Px;
             private float Py;
            private float Pz;
            private bool AceleratingForwards = false;
            private bool AceleratingBackwards = false;
     
     void Update () {
     if(Driveble){
             if(Input.GetKey(KeyCode.W))
             {
            Px = transform.position.x;
             Py = transform.position.y;
            Pz = transform.position.z;
                 if(isTouching){
                     if(currentacelerationF < MaxAcelerationForwards){
                         currentacelerationF ++;
                         transform.position = new Vector3(Px, Py, Pz += currentacelerationF * Time.deltaTime);
                         }
                 else{}
                 }
                 
                 else{}
                 
             }
             else{
             if(Input.GetKey(KeyCode.S))
             {
            Px = transform.position.x;
             Py = transform.position.y;
            Pz = transform.position.z;
                     if(isTouching){
                         if(currentacelerationB < MaxAcelerationBackwards){
                         currentacelerationB++;    
                 transform.position = new Vector3(Px,Py,Pz -= currentacelerationB * Time.deltaTime);
                             bool AceleratingForwards = true;
                     }
                     else{}
                     }
                     else{}
             }
                 else{
             if(Input.GetKey(KeyCode.A))
             {
             }
                     else{
             if(Input.GetKey(KeyCode.D))
             {
                     
             }
                         else{
                             if(AceleratingForwards == false){
                                 if(currentacelerationF < MaxAcelerationForwards){
                                     if(currentacelerationF > 0.0f){
            Px = transform.position.x;
             Py = transform.position.y;
            Pz = transform.position.z;
                                         currentacelerationF--;    
                 transform.position = new Vector3(Px,Py,Pz += currentacelerationF * Time.deltaTime);}
                                 }
                                 else{
                                     if(currentacelerationF == MaxAcelerationForwards){
                                         if(currentacelerationF > 0.0f){
            Px = transform.position.x;
             Py = transform.position.y;
            Pz = transform.position.z;
                                         currentacelerationF--;    
                 transform.position = new Vector3(Px,Py,Pz += currentacelerationF * Time.deltaTime);}
                                     }
                                 }
                             }
                             else{
                                 if(AceleratingForwards == false){
                                 if(currentacelerationB < MaxAcelerationBackwards){
                                     
                                 }
                                 else{
                                     if(currentacelerationB == MaxAcelerationBackwards){
                                         
                                     }
                                 }}
                             }
                         }
                     }
                 }
             }
         }
         
     }
 }

if you guys could help me I would be grateful.

By the way I haven't finished yet so there's stuff missing.

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 Fattie · Oct 26, 2012 at 12:12 PM 0
Share

just FTR

it is very, very, very, very, very, very difficult to build car rigs.

there is a FULL tutorial of a race car on an island, which unity gives for free. you can read through the 100s and 100s of pages of PDF explaining (very basically) how to make a car move in a video game.

here .. http://unity3d.com/support/resources/tutorials/car-tutorial

download the three TEN $$anonymous$$EGABYTE documentation files and start reading !

youc an also buy pretty goo car rigs for a few dollars o the asset store.

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by ghhwer · Oct 27, 2012 at 10:42 AM

Thank you all but i figured out how to do its just change the lines were I wrote

 transform.position = new Vector3(Px,Py,Pz += currentacelerationF * Time.deltaTime);}

to

 transform.Translate(Vector3.forward * currentacelerationF * Time.deltaTime);

but still thanks for your help!

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
avatar image
0

Answer by hvilela · Oct 26, 2012 at 12:19 PM

Well, there's absolutely no rotate code there and the rotation won't change unless you change it. Check transform.rotation.

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.

Follow this Question

Answers Answers and Comments

10 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

Related Questions

How to make camera position relative to a specific target. 1 Answer

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

How can I make sure two movable objects stay a certain distance away from eachother? 0 Answers

I need help with a script(brauche hilfe mit einen Script) 0 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