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
1
Question by slayer29179 · Oct 16, 2012 at 11:21 AM · gravitymovecontrolssimplemove

Simplemove controls without the gravity

Hey all! This has been bothering me and took me a while to find out but I am making an aircraft vehicle and I have made the controls so it speeds up using simplemove. However simplemove adds gravity and I need to disable the gravity, is there anyway to do this? this is my script so far: (I have taken out some of the extra features such as handbreak etc...)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ private var conversionMetrics : float = 9.2; var vehicleSpeed : float = 0.0; var topSpeed = 120; var tireTraction : int = 3;

 function Update() 
 {
     var controller : CharacterController = GetComponent(CharacterController);
     var moveDirection = transform.TransformDirection(Vector3.forward);
     var curSpeed = vehicleSpeed * Input.GetAxis("Vertical");
         
     //Rotate code
     transform.Rotate(0, Input.GetAxis("Horizontal") * tireTraction, 0);
     
 //~~~~~~~~~~~~~~~~~~~~~~~~~Increase Speed~~~~~~~~~
     if (Input.GetKey("w") || Input.GetKey("up"))
     {
         if (vehicleSpeed < topSpeed)
         {
             vehicleSpeed += 1 * Time.deltaTime * conversionMetrics;
         }
     }
 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~Breaking~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~        
     if (Input.GetKey("s") || Input.GetKey("down"))
     {
         if (vehicleSpeed > 0)
         {
             vehicleSpeed -= 5 * Time.deltaTime * conversionMetrics;
             if (vehicleSpeed == 3)
             {
                 vehicleSpeed = 0;
             }
         }
     }    
     if (Input.GetKey("q"))
     {
         gameObject.transform.position.y += 1 * Time.deltaTime * conversionMetrics;
     }
     
     // Move the controller
     controller.Move(moveDirection * vehicleSpeed);
 }

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

I read on-line that to get rid of the gravity I should use move instead, however the only way I can think to keep it moving is by using a boolean for every action. Is there any other way? please and thank you!

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

2 Replies

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

Answer by aldonaletto · Oct 16, 2012 at 01:18 PM

The parameter passed to SimpleMove is the velocity vector, while Move requires the 3D displacement. In order to convert velocity to displacement, just multiply velocity by Time.deltaTime: this calculates the distance moved at such velocity since last frame.
You could use the "Vertical" axis to control acceleration, but the different effects of accelerating and breaking must be taken into account, using different multipliers for positive and negative acceleration:

 private var conversionMetrics : float = 9.2; 
 var vehicleSpeed : float = 0.0; 
 var topSpeed = 120; 
 var tireTraction : int = 3;
 
 function Update() 
 {
     var controller : CharacterController = GetComponent(CharacterController);
     var moveDirection = transform.TransformDirection(Vector3.forward);
 
     //Rotate code - use Time.deltaTime to get stable results:
     transform.Rotate(0, Input.GetAxis("Horizontal") * tireTraction * Time.deltaTime, 0);
 
     // get the acceleration from the "Vertical" axis:
     var accel = Input.GetAxis("Vertical") * Time.deltaTime * conversionMetrics;
     if (accel > 0){
         accel *= 1; // forward acceleration
     } else {
         accel *= 5; // breaking
     }
     // apply to the vehicle speed, clamping to the limits:
     vehicleSpeed = Mathf.Clamp(vehicleSpeed + accel, 0, topSpeed);
     // calculate the horizontal velocity vector:
     moveDirection *= vehicleSpeed; 
     if (Input.GetKey("q")) // include vertical up velocity:
     {
        moveDirection.y = 1 * conversionMetrics;
     }
 
     // Convert velocity to distance multiplying by Time.deltaTime
     // and Move the character:
     controller.Move(moveDirection * 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 slayer29179 · Oct 16, 2012 at 02:35 PM 0
Share

Thank you Aldo! :D

avatar image
0

Answer by PAEvenson · Oct 16, 2012 at 11:47 AM

You can just remove gravity from Unity. Edit->Project Settings->Physics->Gravity

or go here http://docs.unity3d.com/Documentation/Components/class-PhysicsManager.html

Comment
Add comment · Show 4 · 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 slayer29179 · Oct 16, 2012 at 12:14 PM 0
Share

Thank you for your answer! however my game is an open world game with other vehicles so disabling all the gravity renders them not usable.

avatar image PAEvenson · Oct 16, 2012 at 12:30 PM 1
Share

how about turning off the rigidbody's gravity http://docs.unity3d.com/Documentation/ScriptReference/Rigidbody-useGravity.html

avatar image slayer29179 · Oct 16, 2012 at 12:38 PM 0
Share

I have, I tried different combinations such as Gravity On and $$anonymous$$inematic On, $$anonymous$$inematic off, gravity off, nothing works, but as soon as I switch to $$anonymous$$ove it works but disables my real movement.

avatar image aldonaletto · Oct 16, 2012 at 12:56 PM 0
Share

@PAEvenson, the CharacterController isn't under physics control: Physics.gravity is completely ignored.

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

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

Applying force to my object has no effect. 1 Answer

Switching from SimpleMove to Move 1 Answer

Can someone help me with this Rigidbody2D bug? 1 Answer

Rigidbody wont stop moving!!!! AGH!! 2 Answers

SimpleMove not working on iOS? 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