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 /
This question was closed Jun 17, 2016 at 03:02 PM by FREEZX for the following reason:

Outdated

avatar image
0
Question by FREEZX · Mar 11, 2014 at 10:55 PM · physicsrigidbody2dvelocityfixedupdate

rigidbody2D velocity zero?

I have two scripts, in one of the scripts i set the rigidbody velocity of the object it belongs to, using fixedupdate, like so:

 void FixedUpdate()
 {
     if (Input.GetMouseButton(0))
     {
         vVelocity += vSensitivity * Time.deltaTime;
     }
     else
     {
         vVelocity -= vSensitivity * Time.deltaTime;
     }

     Vector2 velocity = new Vector2(hSpeed, vVelocity);

     transform.right = velocity;
     rigidbody2D.velocity = velocity;
 }



and the other script, which uses the velocity of the rigidbody, referenced through a transform:

 void FixedUpdate()
 {
     if(followTransform.rigidbody2D != null){
         Debug.Log("Has rigidbody with v: "+followTransform.rigidbody2D.velocity);
     }
 }


This just outputs "Has rigidbody with v: (0, 0)", and sometimes (once out of 100 times) gives out the correct value, although the object is clearly moving and the transform is never directly changed.

If i set this second script's execution order to be sooner than the default, everything is working as expected.

Why is this happening and how can i solve it without modifying the execution order?

Comment
Add comment · Show 11
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 highpockets · Mar 11, 2014 at 11:03 PM 0
Share

Have you tried:

 rigidbody2D.velocity.sqr$$anonymous$$agnitude;

That always works for me.

avatar image FREEZX · Mar 12, 2014 at 08:49 AM 0
Share

I think that if the velocity itself is a (0, 0), whichever function i call operates on those values.

avatar image Benproductions1 · Mar 12, 2014 at 09:23 AM 0
Share

@highpockets sqr$$anonymous$$agnitude has nothing to do with the question.

avatar image highpockets · Mar 12, 2014 at 01:54 PM 0
Share

I realize it doesn't directly answer the question, but it gives an alternative to find out the speed of the rigidbody. Correct me if I'm wrong, but that seems to be the goal here. I don't know if it will solve the problem, but sqr$$anonymous$$agnitude has given me good results when I need to find the speed of a rigidbody. Therefore, I think sqr$$anonymous$$agnitude does in fact have relevance here BP1.

avatar image mclankyman · Mar 12, 2014 at 02:07 PM 0
Share

it doesn't, because magnitude is the length of the velocity vector, so is a float value. Sqr magnitude is this length multiplied by itself which is even further away from what the user wants.

$$anonymous$$aybe put the debug.log bit in update rather than fixed update?

Show more comments

0 Replies

  • Sort: 

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

NullReferenceException: UnityEngine.Rigidbody2D.get_velocity() 0 Answers

Character won't move (Fixed) 1 Answer

Velocity from Rigidbody and from Transform don't match for small dt 1 Answer

Convert from m/s to m/fixedFrame 1 Answer

Do rigidbodies (especially 2d) have limits on their velocities? 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