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 gagesaber · Mar 15, 2015 at 02:15 AM · rigidbody2dvelocityaddforce

Rigidbody 2D has velocity but isn't moving after Unity 5 upgrade

I want the player to have a speed equal to that of the screen scroll rate. I have a rigidbody2d whose velocity parameter I set directly every Update so the player moves along with the screen. In 4.6 this was working no problem but after upgrading to 5 for some reason the player stays still even though according to the log it still has velocity.

If I use AddForce in a FixedUpdate the player moves but the rigidbody2d.velocity parameter still says (0,0) so I can't compare it to the max velocity. Also, the whole game was coded so far just directly changing velocity so I'd like to keep that if possible.

Any ideas on what could be the problem? Or if this can't be fixed is there an easy way to use AddForce to result in a constant velocity?

 void Update(){
      //set the base player speed to the screen scroll rate
                 float xSpeed = scrollRate;
                 Vector2 newSpeed = GetComponent<Rigidbody2D>().velocity;
                 newSpeed.x = xSpeed;
         
         //set the player's speed
                 //GetComponent<Rigidbody2D>().AddForce(newSpeed, ForceMode2D.Force);
                 GetComponent<Rigidbody2D> ().velocity = newSpeed;
                 print ("speed set:" + newSpeed);
                 print ("speed act:" + GetComponent<Rigidbody2D>().velocity);
 }
 


EDIT:

Here's the code in Fixed Update:

 void FixedUpdate() {
         //set the base player speed to the screen scroll rate
         float xSpeed = sm.realScrollRate;
         Vector2 currentSpeed = GetComponent<Rigidbody2D>().velocity;
 
         //set the player's speed
         if(currentSpeed.x < xSpeed)
             GetComponent<Rigidbody2D>().AddForce(Vector2.right * 250f, ForceMode2D.Force);



CONFIRMED ISSUE IS WITH UNITY 5

I have Unity 4.6 still on my PC and loaded a backup of my project and the player runs just fine when directly setting the velocity in Update().

Does anyone know what was changed in Unity 5 that would make this no longer function?

Comment
Add comment · Show 3
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 Jack-Does · Mar 15, 2015 at 08:15 PM 0
Share

im having similar issues. im using the GetComponent().AddForce on click (or tap on mobile) when i click, ins$$anonymous$$d of adding force. the player instantly jumps to a new position. like transform.Translate would. also gravityScale on the rigidbody is pulling up ins$$anonymous$$d of down. im thinking of sticking with 4.6 for a while, too bad. i was looking forward to all the cool new features.

avatar image gagesaber · Mar 15, 2015 at 08:38 PM 0
Share

@Jack-Does -

Does your player have an Animator on it? I think through a lot of trial and error I figured out what the problem was for me at least. If you disable "Apply Root $$anonymous$$otion" in the Animator component then the player should animate normally.

I'm guessing that the "Root $$anonymous$$otion" is trying to force the player to translate according to the animation but to be honest I haven't read the documentation on it as thoroughly as I should. If anyone is able to explain the Root $$anonymous$$otion concept better than the docs I would appreciate it.

avatar image Jack-Does · Mar 15, 2015 at 08:46 PM 0
Share

I literally just figured this out myself and came back to tell you.

2 Replies

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

Answer by gagesaber · Mar 15, 2015 at 11:25 PM

Looks like the problem is that with the upgrade to Unity 5 all Animator components had the "Apply Root Motion" option enabled which I believe makes it so that the object moves according to it's animation rather than according to physics. Disabling this option allows the object to be manipulated by physics properly.

If I am misunderstanding the Root Motion concept I would appreciate any further explanation.

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 DDLacerda · Mar 25, 2015 at 04:54 PM 0
Share

thanks! helped me

avatar image FreemanPixelz · May 31, 2015 at 10:20 AM 0
Share

It helped me too! I didn't find any explanations about Root $$anonymous$$otion on Unity 5...

avatar image Grievemourne · Jan 19, 2016 at 09:38 PM 0
Share

Just giving my own thanks; I can deal with my own errors, but figuring out these kinds of problems make me sweat profusely.

avatar image hhhung · Aug 25, 2017 at 09:57 AM 0
Share

I was going crazy about it. You are my savior!

avatar image
0

Answer by hoarfrost31 · Oct 19, 2017 at 10:02 AM

I had the same problem but also wanted to keep root motion on and turned out that problem was with Update mode and not root motion. Set Update mode to normal and you will be fine. If can't do that then you will need to set root motion on and off dynamically.

Cheers!

Comment
Add comment · 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

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

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

move 2d character affected by physics with velocity and/or add force 2 Answers

,Rotate a gameobject around another while being attracted by its gravity 1 Answer

Jumping with Rigidbody.AddForce not working? 1 Answer

I need Help with AdForce pls :( 1 Answer

Adding force to rigidbody2d to slide 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