Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by EstherDarling · Nov 03, 2016 at 02:15 PM · physicsrigidbodyvector3velocity

Rigidbody.velocity Movement code produce wildly different gravity interactions

Main character movement using Rigidbody.velocity and two methods of control for player preference. The character moves via WASD (either locally or globally) and rotates to face the direction of the mouse pointer. I can confirm that the aiming script does not manipulate the problem, it is just this script.

The problem I am facing is that the two methods interact with the player differently, as intended, however while 'Scheme2' correctly follows physics (namely gravity, force modifiers etc), 'Scheme1' has this effect where the character floats extremely slowly towards the ground after moving off a ledge.

No amount of applied force or the absense of applied forces seem to affect the rate of fall. As stated, 'Scheme2' interacts as intended with gravity.

Why does 'Scheme1' fall at an absurdly slow rate?

My code for the movement script is posted below:

 public class PlayerMovement : MonoBehaviour 
 {
     public float speed = 0.0f;
     private Rigidbody PhysicsBody;
 
     //Relevant to current control scheme testing
     private bool Scheme1; //Default Control Scheme: Screen-Based
     private bool Scheme2; //Alternate Control Scheme: Pointer-Based
 
     void Start ()
     {
         PhysicsBody = GetComponent<Rigidbody>();
 
         //At the start of the game set Control Scheme to Default
         Scheme1 = true;
         Scheme2 = false;
     }
 
     void FixedUpdate ()
     {
         if (Scheme1 == true)
         {
             var PlayerInput = new Vector3 (Input.GetAxis ("Horizontal"), 0.0f, Input.GetAxis ("Vertical"));
             PhysicsBody.velocity = (PlayerInput * speed * Time.deltaTime);
         }
 
         if (Scheme2 == true)
         {
             //forward
             if (Input.GetAxis ("Vertical") > 0) 
             {
                 PhysicsBody.velocity = (transform.forward * speed * Time.deltaTime);
             }
 
             //back
             if (Input.GetAxis ("Vertical") < 0) 
             {
                 PhysicsBody.velocity = (-transform.forward * speed * Time.deltaTime);
             }
 
             //right
             if (Input.GetAxis ("Horizontal") > 0) 
             {
                 PhysicsBody.velocity = (transform.right * speed * Time.deltaTime);
             }
 
             //left
             if (Input.GetAxis ("Horizontal") < 0) 
             {
                 PhysicsBody.velocity = (-transform.right * speed * Time.deltaTime);
             }
         }
     }
 
     void OnGUI ()
     {
         if(GUI.Button(new Rect(50,50, 200, 50), "Default"))
         {
             Scheme2 = false;
             Scheme1 = true;
         }
         if(GUI.Button(new Rect(50,120, 200, 50), "Alternate"))
         {
             Scheme1 = false;
             Scheme2 = true;
         }
     }
 }
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 TreyH · Nov 03, 2016 at 03:42 PM 0
Share

It's worth mentioning that manually changing a Rigidbody's velocity is very rarely warranted. You are interfering with the normal physics calculations by overwriting their natural values with your own -- there is a reason for AddForce and Force$$anonymous$$odes.

One reason for this being that regardless of your input, you are setting its Y component of velocity every physics update. That means that whatever gravitational influence Unity has calculated for your character, your are erasing it with your own.

If there is no input by you (the player), then you are assigning a Zero vector for its physical velocity. How quickly do you expect that to fall? As for the slow speed, this can either be from Input's being floats and your input axis slowly fading to zero or Unity's acceleration still factoring in slightly (which you did not change).

0 Replies

· Add your reply
  • Sort: 

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

getComponent().Velocity always returns 0? 2 Answers

Proper way to set a RigidBody's maximum velocity 1 Answer

Slow down a character while they are midair while keeping their original velocity 0 Answers

Check/Change velocity of an object 0 Answers

Make a "Balloon" that floats upwards but slows as it gets higher 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