• 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
Question by ClanDestiny · Oct 02, 2015 at 06:00 PM · c#physicsvelocity

Velocity Behavior Question

Preface: Thank you to the people who took the time to answer my other post (redirects to here), however it seems to have fallen prey to an error and the comments/replies on it are not visible to me or a moderator.

Hello,

Please excuse me if this is not an appropriate question (i.e. specific enough to Unity) but I am asking in case it is due to something about the engine that I am not aware of. This is after looking up velocity in the broader sense, where speed is the absolute value of that vector and so on. With that definition in mind I am having trouble understanding the following behavior:

In writing my movement script I got to introducing the bool switch for "sprint". By increasing maxSpeedCurrent I was not getting to the sprinting cap, so I started playing with the value of force being applied on movement, from 15 to 1500. The cap works, however...

If I Debug.Log("Velocity: " + Mathf.Abs(rigBody.velocity.x)); I get up to 3, whether at 15 force or 1500 - the speed at which the character traverses space at that 3 value, however, is vastly different. How can it be that the same velocity represents different rates of movement? The above Debug snippet technically returns "speed" rather than velocity, but if I debug velocity I get a vector with one of its parameters behaving the same way: moving up to 3, no matter the force or speed.

Here is the code in case it helps to clarify (I read that modifying velocity per frame is not recommended and will look into that tomorrow - however it's going on 300am and I work tomorrow - I just mean that's not the focal issue here)

 void FixedUpdate() 
     {    
         horizontal = Input.GetAxis("Horizontal");
         vertical = Input.GetAxis("Vertical");
         sprint = Input.GetButton("Sprint");
         if(horizontal == 0.0f && vertical == 0.0f) {inMovement = false;}
         maxSpeedCur = maxSpeedBase;
         if(sprint == true) maxSpeedCur += 1.5f;
 
         if(horizontal != 0.0f)
         {        
             if(horizontal > 0.0f) lastMoveInput = "right";
             else if(horizontal < 0.0f) lastMoveInput = "left";
             inMovement = true;
             
             if(horizontal * rigBody.velocity.x < maxSpeedCur)
             {
                 rigBody.AddForce(Vector2.right * horizontal * moveForce);
             }
 
             if(Mathf.Abs(rigBody.velocity.x) > maxSpeedCur)
             {
                 rigBody.velocity = rigBody.velocity.normalized * maxSpeedCur;
             }            
         }
 
 Debug.Log ("Max Speed Current: " + maxSpeedCur);
         Debug.Log ("Velocity Vector: " + rigBody.velocity);
         Debug.Log ("Velocity X: " + Mathf.Abs(rigBody.velocity.x));
 }

To give a concrete example of how I went about testing:

Setup: - Player Object (CircleCollider2D, Rigidbody2D, Linear Drag 5) - PlayerMovement script containing the above code, attached to Player Object - Cube andsphere background for reference

Test 1: - moveForce set to 15.0f; - Start game and move with D - Output is 3 velocity - Time taken to traverse cube platform is about 4 seconds.

Test 2: - moveForce set to 1500 - Start game and move with D - Output is still 3 velocity - Time taken to traverse cube platform is less than one second.

So, to reiterate why this is confusing: speed should be the magnitude of the velocity vector, but the same velocity value is giving different results.

Other Post for reference if admins need it to bug hunt (redircts to here): http://answers.unity3d.com/questions/1075183/understanding-velocity.html

Comment

People who like this

0 Show 0
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

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

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

Related Questions

Using Lerp in a Constant Moving Object 1 Answer

GameObject disappears when velocity is set to (near) zero. 1 Answer

Simulating Fighter Jet Physics (with addForce () ) 2 Answers

Problem Trying to Apply Non-Kinematic Velocity to Rigidbody 0 Answers

Fps Movement Velocity Decrease 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