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 thesquareof4 · Nov 05, 2010 at 06:56 AM · movementphysicscar

Unity car script problem

I am making a car game in Unity and I have created a JavaScript script that lets me move the car around. The scripts works fine unless the car goes over a bump or hill. It will then fly off into the air, regardless of weight and gravity.

I'm reasonably sure this is because transform.translate includes the rotation so if the car is looking up then it will move up because the z axis is pointing up.

The code for the car is:

var speed = 0.0;

var maxSpeed = 6; var minSpeed = -0.5;

var accelerationSpeed = 0.0;

var turnSpeed = 0.0;

var frontLeftWheel : Transform; var frontRightWheel : Transform; var steeringWheel : Transform; var maxSteerAngle = 30;

function Update () { transform.Translate (0, 0, speed); transform.Rotate (0, Input.GetAxis ("Horizontal") *turnSpeed, 0);

var rotation = Input.GetAxis ("Horizontal") * maxSteerAngle; frontLeftWheel.localEulerAngles = Vector3 (0, rotation, 0); frontRightWheel.localEulerAngles = Vector3 (0, rotation, 0); steeringWheel.localEulerAngles = Vector3 (43.99999, 0, -rotation);

getMoveSpeed(); getTurnSpeed();

}

function getTurnSpeed() { turnSpeed = accelerationSpeed;

if (accelerationSpeed <= 0.1)
{
    turnSpeed = 0.1;
}
if (accelerationSpeed == 0)
{
    turnSpeed = 0;
}
if (accelerationSpeed < 0)
{
    turnSpeed = -1;
}

}

function getMoveSpeed() { speed = accelerationSpeed; if(Input.GetKey("up") & (speed < maxSpeed)) { accelerationSpeed += 0.008; }

if (!Input.GetKey("up") & (speed > 0)) {

 if  (accelerationSpeed &gt; 0 &amp; !Input.GetKey("down"))
 {       
     accelerationSpeed -= 0.004;
     if (accelerationSpeed &lt; 0.004)
     {
         accelerationSpeed = 0;
     }
 }

}

if(Input.GetKey("down") & (speed > minSpeed)) { accelerationSpeed-= 0.008; }

if (!Input.GetKey("down") & (speed < 0)) {

 if  (accelerationSpeed &lt; 0 &amp; !Input.GetKey("up"))
 {       
     accelerationSpeed += 0.004;
     if (accelerationSpeed &gt; 0.004)
     {
         accelerationSpeed = 0;
     }
 }

}

if (Input.GetButton("Jump")) { if (accelerationSpeed > 0) { accelerationSpeed -= 0.05; } if (accelerationSpeed < 0) { accelerationSpeed = 0.0; } }

} I know its messy but I'm only year 10

If anyone has any ideas on what my problem could be or a better script could they please post it. Thanks

Comment
Add comment
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

4 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by kop4 · Jun 21, 2011 at 08:57 PM

I think adding a rigid body would solve it, but Im not sure...

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 frankrs · Jul 12, 2012 at 03:01 AM

wow, you are a talented ten year old. Maybe try using the wheel colliers

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 hamzah · Aug 22, 2012 at 09:22 AM

Wow!! :) I tried your script but yes there is a problem. I also modified it that did not work :( So if i was you I will make another script. Sorry I cant help.

Comment
Add comment · Show 1 · 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 AlucardJay · Aug 22, 2012 at 09:23 AM 0
Share

Please don't post comments as answers. Post comments by clicking the [add new comment] button, a window then open for you to type in. Answer fields are for answers only, as this is a knowledge base.

avatar image
0

Answer by hamzah · Aug 22, 2012 at 09:26 AM

Wow!! :) I tried your script but yes there is a problem. I also modified it that did not work :( So if i was you I will make another script. Sorry I cant help.

Comment
Add comment · Show 1 · 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 AlucardJay · Aug 22, 2012 at 09:27 AM 0
Share

Please don't post comments as answers. Post comments by clicking the [add new comment] button, a window then open for you to type in. Answer fields are for answers only, as this is a knowledge base.

Also, until your karma rises, all questions and comments have to be approved by a moderator before it is published, so you'll have to wait until someone approves it before it can be seen.

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Car Movment Script not fully working!!!!!!! 1 Answer

Strange behavior with the Unity car? 0 Answers

Hit problem unity 1 Answer

Car Movment Script not fully working!!!!!!! 0 Answers

Objects stuck dragging across floor 1 Answer


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