bloobchube
bloobchube

Reputation: 39

Unity2D: Rigidbody2D.AddForce won't work when I add a collider

In Unity, I have a player where you press A and D to move left and right, and Space bar to jump (I am also trying to add touch controls). When I add a collider2d to my Player object, the object will not allow me to use Rigidbody2D.AddForce. It just doesn't move my character at all. Anybody know why?

PS: I know it is nothing with my input, because when I just edit the position directly (e.g. player.transform.position.y += 1) it works, but it looks like the player is just teleporting so I don't want to do that.

Upvotes: 3

Views: 900

Answers (2)

Galal Hassan
Galal Hassan

Reputation: 76

Maybe you can post some code or images of the settings of your player?

However, there may be many issues why its not affecting your player.

  • Maybe your player is colliding with something that is preventing the rigid body to move it.
  • Maybe the force you are adding is not enough to move the player.
  • Maybe there is something in your code.
  • Maybe the isKinemtic is set to true?

I hope this helps.

Upvotes: 0

Nain
Nain

Reputation: 1232

You need to set isKinematic property of RigidBody to false. Because If isKinematic is enabled, Forces, collisions or joints will not affect the rigidbody anymore. The rigidbody will be under full control of animation or script control by changing transform.position. reference to unity documentation http://docs.unity3d.com/ScriptReference/Rigidbody-isKinematic.html

Upvotes: 2

Related Questions