Search Unity

[SOLVED] Player teleports when using Rigidbody.AddForce

Discussion in 'Physics' started by Snipe76, Apr 7, 2018.

  1. Snipe76

    Snipe76

    Joined:
    May 23, 2017
    Posts:
    12
    When I hit an enemy, I use a function that pushes the player away from the enemy.
    But for some reason, the player teleports instead of being pushed.
    Pushing:
    Code (CSharp):
    1.         Vector3 direction = (transform.position - enemyPos).ZeroY().normalized;
    2.         _body.AddForce(direction * forceToPush, ForceMode.Impulse);
    But the funny thing is that I use AddForce for jumping and for jump platforms on the Y axis and it works perfectly. Why is that?

    Jumping:
    Code (CSharp):
    1.  
    2.         Vector3 _jumpingVector = new Vector3(0, jumpSpeed, 0);
    3.          _body.AddForce(_jumpingVector, ForceMode.Impulse);

    Jump Platform:
    Code (CSharp):
    1.         _playerBody.velocity = Vector3.zero;
    2.         _playerBody.AddForce(directionToBounce * forceForBounce);

    I don't use any Standard assets for controlling the player (I know they are buggy)
    The player is not Kinematic and uses gravity.
    Players animator is not on Animated physics.
    Rigidbody is not constrained.
    My movement is not resetting the X and Z axis. (I even tried removing the movement script to test that)
     
    Last edited: Apr 8, 2018
  2. Snipe76

    Snipe76

    Joined:
    May 23, 2017
    Posts:
    12
    I have figured what have been constraining the player and instead of using physics, he teleported.
    Something with his animation that did not let him be physically pushed ( I disabled the animator and he is being pushed again. )

    Edit: the cause of it was "Apply Root Motion" in the Animator.
     
    Last edited: Apr 8, 2018
    JDeyby and Khajam like this.