Search Unity

Apply a force to a Rigid Body while an animation is being controlled by user input

Discussion in 'Physics' started by EduAlvarado, Oct 29, 2020.

  1. EduAlvarado

    EduAlvarado

    Joined:
    May 11, 2020
    Posts:
    11
    Hello everyone,

    My case is the following. I have a GameObject with a CharacterController and a RigidBody (with isKinematic and Use Gravity set to false). I can control the character with keyboard inputs, and when it moves, a walking animation is executed.

    At the same time I press the keys and walk, I want to apply a force to the rigid body (more specifically, a torque, to tilt the character then is walking up-hill for example). But here comes the problem:
    • It seems that providing an input (pushing the up-arrow in the keyboard and walking) and the torque application are incompatible. That means: Or I walk, or the RigidBody moves. You can see in the following .gif how both actions "fight" to each other.


    The force that I am applying in the gif is an example and is exaggerated; It would be a force that is very small and would depend on the terrain steepness, to tilt the character with respect to the terrain. That is something that I have already done.

    But! How to apply such force at the same time I control my character and the animation takes place?

    Thank you!