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 RealMTG · Jun 22, 2015 at 04:19 PM · rigidbodyvelocitymagnitude

Rigidbody.velocity.magnitude only returns value of the Y axis

Hi

While trying to get animator on my playing working I noticed that rigidbody.velocity.magnitude only returns a proper number when I am jumping. When I am moving it just gives me numbers like "1.66893E-05" and if I have been taught correct, that means 0. I've searched for how I can get the velocity of the rigidbody and all result in rigidbody.velocity.magnitude but that is not working. Am I doing something wrong here?

I am not going to show any code either because I don't know what code I could show.

Thanks in advance

Comment
Add comment · Show 4
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 Bonfire-Boy · Jun 22, 2015 at 04:53 PM 0
Share

Have you tried logging the value of the velocity? And how are you moving the rigidbody? If for example you move it laterally by adjusting the transform's position directly, but jump by applying an upwards force or adjusting the velocity directly, then I might expect something like what you're describing.

avatar image RealMTG · Jun 22, 2015 at 05:01 PM 0
Share

@Bonfire Boy I am moving the rigidbody using $$anonymous$$ovePosition. So is there a way I can get the velocity using this method?

avatar image rhbrr5hrfgdfgw · Jun 22, 2015 at 05:02 PM 0
Share

have you tried addforce? it should work

avatar image RealMTG · Jun 22, 2015 at 05:06 PM 0
Share

@rhbrr5hrfgdfgw I've used it before and might be able to implement it later. I can't do it right now but if I get it working later, I'll come back with a good comment. Else I'll just ask for more help. :P

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Eno-Khaon · Jun 22, 2015 at 05:29 PM

Taking a note from the comments, if you're using rigidbody.MovePosition() to move around, you're not applying any change to your velocity. Therefore, while your velocity IS zero, your rate of movement simulating velocity would be the speed at which you're directly moving the object.

For example, if you're using something like:

 //C#
 
 Rigidbody rb;
 public float speed;
 
 void Start()
 {
     rb = GetComponent<Rigidbody>();
 }
 
 void FixedUpdate()
 {
     rb.MovePosition((transform.position + Vector3.right * speed) * Time.deltaTime);
 }

as your means of movement (without information, I'm speculating a bit), this would be moving on the X axis at a rate of "speed" units per second.

This would not be counted as velocity, but your distance moved per second would be exactly as far as you tell it to be.

As @rhbrr5hrfgdfgw suggested, it would probably be preferable to use AddForce() instead to control rigidbody movement, as that actually applies motion through the object's velocity instead.

  //C#
  
  void FixedUpdate()
  {
      // Based on object's mass. The higher the mass, the less impact the force has.
      rb.AddForce(Vector3.right * speed);
      // Ignoring object's mass. Anything of any weight accelerates at the speed listed.
      //rb.AddForce(Vector3.right * speed, ForceMode.Acceleration);
  }

It also requires less extraneous code.

Comment
Add comment · Show 3 · 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 RealMTG · Jun 23, 2015 at 01:16 PM 0
Share

I have been trying to switch to AddForce but I can't. I added

 moveDirection(Vector3) = new Vector3(Input.GetAxisRaw("Horizontal"), 0, Input.GetAxisRaw("Vertical"));
 
                 rig.AddRelativeForce(moveDirection * movementSpeed * Time.deltaTime);

to FixedUpdate but the player just stands there. It only moves when I jump and then the player slows down and is uncontrollable. What could cause this?

avatar image Eno-Khaon · Jun 23, 2015 at 06:27 PM 0
Share

Immobility on the ground could be the result of friction, then. Physics materials can let you modify the default PhysX values for friction interaction between objects, though working with various shapes and sizes can have unexpected results. For instance, cubes would have a very large surface contact area potential, so they often exhibit much greater friction.

avatar image RealMTG · Jun 23, 2015 at 09:22 PM 0
Share

@$$anonymous$$o $$anonymous$$haon I am using a capsule collider and disabled everything that had to do with physics materials and it does no difference. I even tried to apply a zero friction material and that also did nothing.

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

24 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

Related Questions

void OnCollisionEnter(Collider other) { if (Rigidbody.velocity.magnitude > 5) {...} - In "Rigidbody.velocity.magnitude" asks to give link to the object??? 2 Answers

Adding player velocity to projectile not working 0 Answers

Why is this loop infinite? 1 Answer

increase float when another one decreases 1 Answer

Rigidbody magnitude 3 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