6

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?

Seth Battin
  • 5,509
  • 3
  • 27
  • 43
Daarwin
  • 829
  • 3
  • 25
  • 42
  • We would need to see your implementation of ZombieBoyController.AddForceAtPosition() to have the full story. – Kelly Thomas Jan 17 '14 at 15:35
  • 1
    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. – DMGregory Jan 10 '16 at 14:36
  • 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.5mv^2 – Anonymous Anonymous Nov 19 '17 at 13:24
  • can you share a code or inspector? – virtouso Sep 03 '19 at 18:23

2 Answers2

0

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);
aglassman
  • 141
  • 2
  • 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.

    – Daarwin Jan 17 '14 at 20:00
  • Why do you want to use AtPosition? – aglassman Jan 17 '14 at 20:49
  • 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? – Daarwin Jan 18 '14 at 19:12
-1

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.

Gnemlock
  • 5,263
  • 5
  • 28
  • 58
Adam R. Grey
  • 245
  • 2
  • 8