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 Xercium · Jul 25, 2016 at 09:32 AM · rigidbody2daddforce

Rigidbody2D AddForce Impulse not working on X axis

Hi guys,

Can't figure out what I'm doing wrong. When my player hits a wall I want him to bounce back so I execute this code: [code=CSharp]Debug.Log("You hit a wall. " + new Vector2(direction xKnockback, yKnockback)); gameObject.transform.parent.GetComponent().AddForce(new Vector2(direction xKnockback, yKnockback), ForceMode2D.Impulse);[/code]

alt text

Now the strange part is, in the Y is working, the player is getting sky rocketted because I set the x and y knockback values very high, So I know it's working for the Y axis. But in the X direction it's just standing still. What could I be doing wrong?

alt text

Thanks for the help!

bb0de44740803920f4e1f53aa056ae09.png (4.7 kB)
8c9d02d0869627a1e130f226b7a6caf9.png (15.3 kB)
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 hnrqndrd · May 18, 2017 at 12:24 AM 0
Share

Did you find out? :( I also have this issue.

5 Replies

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

Answer by hnrqndrd · May 18, 2017 at 07:29 AM

Did you find out? :( I also have this issue.

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 Xercium · May 18, 2017 at 11:23 AM 0
Share

I did not find a solution and my program got halted :( maybe it will start up again. If I find a solution I'll let you know. Please do the same. Good luck

avatar image hnrqndrd Xercium · May 18, 2017 at 11:43 PM 0
Share

@Xercium I just solved it. This link helped me.

What I basically did was removing the game object manually in the editor. Then I recreated it from the scratch (nothing too complicated, only 2D collider, rigidbody and animator) and added the same script. So yes, it is a bug in Unity (currently using 5.6.1f1).

avatar image Xercium hnrqndrd · May 19, 2017 at 11:08 AM 0
Share

Thank you for sharing mate!

I will test it out as soon as I can!

avatar image
4

Answer by Jackal14 · Jan 17, 2019 at 03:34 PM

I came across this error too and i think i found exactly, what the problem was, i'm not sure about disabling the animator because Apply Root Motion was already marked off in my project.

The exact reason for this problem is that your X axis component of RIgidbody is already being updated elsewhere at the same time when you are trying to create this KnockBack or Bounce. So check if there is any Conflict for X axis movement in the same script or if any other script is trying to access it. This Resolved it for me. Hope this helps!!

And use Impulse instead of Force For ForceMode2D

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

Answer by plof27 · Jun 12, 2018 at 09:50 PM

I know I'm 8 years late on this, but I came across this post because I ran into the same problem. There was a thread here which actually had a functional solution. While remaking the game object can fix the problem, the real thing you need to do is uncheck Apply Root Motion on the object's Animator component. For some reason, this causes weird locking on some, but not all, axes even if there is no parent object in the hierarchy. Hopefully this helps any other lost souls who find themselves here years in the future.

Comment
Add comment · Show 2 · 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 nuubje006 · Jun 13, 2018 at 05:19 AM 0
Share

This is some weird behavior. If I pick up my project again I will test it out. I hope it helps some people out! Tnx for you solution.

avatar image path14 · Oct 29, 2018 at 02:32 PM 0
Share

I had to login and thank you! so, THAN$$anonymous$$ YOU! :)

avatar image
0

Answer by Joe_27 · Feb 03, 2019 at 11:32 PM

I'm having this problem too. But none of the above helped.

It's not the animator. And nothing else is updating my rigidbody as far as I can tell. AddForce simply doesn't affect the X-axis at all, while the Y-axis works normally.,I'm completely stumped by this problem with AddForce and the X-axis...

My X axis completely ignores AddForce, but my Y axis is completely normal. I'm at my wits end with this problem. None of the previous comments solved this problem.

This is everything involving my horizontal movement script. It works just fine and moves my character normally.

 float h = Input.GetAxisRaw("Horizontal");
 
         if (h * GetComponent<Rigidbody2D>().velocity.x < maxSpeed)
             GetComponent<Rigidbody2D>().AddForce(Vector2.right * h * moveForce);
         
 
             if (Mathf.Abs(GetComponent<Rigidbody2D>().velocity.x) > maxSpeed)
             GetComponent<Rigidbody2D>().velocity = new Vector2(Mathf.Sign(GetComponent<Rigidbody2D>().velocity.x) * maxSpeed, GetComponent<Rigidbody2D>().velocity.y);



And this example command will affect my Y Axis but does absolutely nothing to my X axis no matter how ridiculous the Force, like the 999 in the example, but even something like 1 or 2 will make my character "jump" along the Y. While even the maximum value possible won't move my character at all.

 if (Input.GetButtonDown("Dash"))
         {
             
             rb.AddForce(new Vector2(999, 0), ForceMode2D.Impulse);
         }


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

Answer by AustinSyu · Apr 25, 2019 at 01:15 AM

Same issue, can't use addforce and root motion to affect the x axis at the same time. "Recreate a object" doesn't work for me.

My solution: Disable the animator before addforce than after a certain time enable it again. This is OK for my project but maybe not for yours...

Not sure what they are doing leaving such a ridiculous bug for years! But sure about that after some more little games, I'd better move on to learn another game engine.

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

70 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 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 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

RigidBody2D velocity randomly drops to zero 1 Answer

AddForce rigidbody 2d not moving object 2 Answers

Constant speed in 2d game. 1 Answer

Unable to AddForce on a game object containing a RigidBody2D and a HingeJoint2D? 1 Answer

RigidBody2d AddForce not working 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