5
\$\begingroup\$

I'm using Rigidbody2D for some game objects. It seems that when I AddForce() or AddForceAtPoint(), the game objects are mostly affected on the Y axis and hardly at all on the x axis. I don't understand why. To really get any effect on the x axis, I need to have a very strong force like *10 000. But the effect on the y axis is then extremely strong and shoots the object out of screen, yet only nudges the game object on the x scale.

I believe that the problem with the y axis is because I use .velocity to move the character. But I don't know how to change the velocity directly without doing that. What should I do to use both forces and set velocity on the same object?

\$\endgroup\$
  • \$\begingroup\$ We would need to see your implementation of ZombieBoyController.AddForceAtPosition() to have the full story. \$\endgroup\$ – Kelly Thomas Jan 17 '14 at 15:35
  • 1
    \$\begingroup\$ You might find this answer helpful - it discusses the pitfalls of setting velocity directly, since that tends to override any other physics influences on the object. You'll likely want to move your character with forces & accelerations if you want them to react to outside forces correctly. \$\endgroup\$ – DMGregory Jan 10 '16 at 14:36
  • \$\begingroup\$ Your problem with the "required" high forces is, that you aren't applying them "over a distance" - meaning, you aren't actually doing "work" on the object. I'll just suggest to look up the words "Force", "Work" and "Kinetic Energy" in Wikipedia! But here some formula you will need: F = ma; W = Fd; and E = 0.5*m*v^2 \$\endgroup\$ – Anonymous Anonymous Nov 19 '17 at 13:24
0
\$\begingroup\$

You're using the AddForceAtPosition, which will apply a force to a particular position on the rigid body. You are entering the direction vector on the zombie rigidbody as a position. You should just use the following:

rigidbody2D.AddForce (direction.normalized * force);
\$\endgroup\$
  • \$\begingroup\$ I have the same problem with the y axis wether i use AddForce or AtPosition. But it is the AtPosition that i want to use. I just realized that the problem with the y axis is because i use .velocity to move the character. But i dont know how to do it without changing the velocity. \$\endgroup\$ – Daarwin Jan 17 '14 at 20:00
  • \$\begingroup\$ Why do you want to use AtPosition? \$\endgroup\$ – aglassman Jan 17 '14 at 20:49
  • \$\begingroup\$ Im using at position because i want a force at one point to affect all objects within distance. Why do you seem to think that this is strange? \$\endgroup\$ – Daarwin Jan 18 '14 at 19:12
-1
\$\begingroup\$

AddForceAtPosition is the function of RigidBody, right? It would appear that you're calling it incorrectly; it should be force first, then position.

For more information, See the API reference for Rigidbody.AddForceAtPosition.

\$\endgroup\$
  • \$\begingroup\$ Uhm no, i just switched the places in the wrapping method. I added it to the question. Sorry. \$\endgroup\$ – Daarwin Jan 17 '14 at 18:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.