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 TheRichardGamer · Nov 16, 2013 at 07:12 PM · carrotate objectvehiclekey pressed

How to rotate a object

I want to rotate my car when I either press A or D, but it doesn't work with my code, what is the problem with my code?

 var RiderSpawn : Transform;
 
 var FinalRiderSpawn : Transform;
 
 var Player : Transform;
 
 var IsRiding : boolean = false;
 
 var MovementScript : CharacterMotor;
 
 var DrivingSpeed : float;
 
 var DefaultPlayerRotation : Quaternion;
 
 var GotOut : boolean = false;
 
 var TruckCollider : Collider;
 
 var TruckCollider2 : Collider;
 
 var Truck : GameObject;
 
 var IsDriving = false;
 
 function Start () {
 
 }
 
 function Update () {
 
 if(IsRiding == true){
 Player.position = RiderSpawn.position;
 Player.rotation = RiderSpawn.rotation;
 }
 
 else
 
 if(IsRiding == false && GotOut == true){
 Player.rotation = (DefaultPlayerRotation);
 GotOut = false;
 }
 
 
 
 if(Input.GetKey(KeyCode.W) && IsRiding == true){
 
 Truck.transform.Translate(Vector3.right * DrivingSpeed * Time.deltaTime); //The reason why I use ".right" instead of forward is because it goes to the left when I use ".forward" . So if you know how to fix this as well, it would mean a lot to me
 IsDriving = true;
 }
 
 if(!Input.GetKey(KeyCode.W)){
 
 IsDriving = false;
 
 }
 
 if(Input.GetKey(KeyCode.A)){
 
 Truck.transform.Rotate(Vector3.left * DrivingSpeed * Time.deltaTime);
 
 }
 
 if(Input.GetKey(KeyCode.D)){ 
 
 Truck.transform.Rotate(Vector3.back * DrivingSpeed * Time.deltaTime);
 
 }
 
 
 
 
 }
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by robertbu · Nov 16, 2013 at 09:49 PM

I don't know your scale, but your are using 'DrivingSpeed' for both forward movement and for rotation. There should be two separate variables, or at least rotation should be a factor multiplied by 'DrivingSpeed'. I don't know your scale here, but typically folks build things at around a unit or two in size, which means 'DrivingSpeed' would be around 2.0 give or take. Your angle will be degrees per second. So if these are the kinds of values you are using, then you will only turn at two degrees per second ... really slow. Try creating a turn factor and start with a value of 45. So your code could would be:

 Truck.transform.Rotate(Vector3.left * DrivingSpeed * turnFactor * Time.deltaTime);
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 TheRichardGamer · Nov 17, 2013 at 03:00 PM 0
Share

Thanks, but when I drive forward my vehicle doesn't have a smooth effect, it kinda buffers. I use Translate and I want a smooth effect when I drive, how do I make a smooth effect with Translate?

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

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

Related Questions

fast forward physic vehicles 0 Answers

Vehicle programming source 5 Answers

Car Collision Damage 1 Answer

Need for speed like physics using Edy's vehicle physics? 1 Answer

How can i import a new car in edy's vehicle physics? 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