News Forums RAIN General Discussion and Troubleshooting Knock Back using addforce on rigidbody

This topic contains 2 replies, has 2 voices, and was last updated by  leochou 1 year, 7 months ago.

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
  • #5662


    I’m trying to add force on the ai’s rigidbody to let it move back in the custom action script when it got hit, but it doesn’t work at all.

    I can’t find any information about using physics system by rain, and I even don’t know if it is possible to knock back ai by add force on its rigidbody.

    This what I tried in the custom action called “GetHitMove”:

    aiRig = ai.Body.GetComponentInChildren<AIRig>();
    myRigidbody = aiRig.AI.WorkingMemory.GetItem<Rigidbody>(“MyRigidbody”);

    Can somebody explains to me what is wrong or there are better ways to implement this function(knock back)?



    It is difficult to use physics in conjunction with AI control. The basic motor assumes that AI is moving based on either root motion or “meat hook” style movement, and that physics are essentially turned off. To do what you want using physics, you will probably need to:
    1) recognize the physics impact, much like what you are doing in your example. I’m not sure that should be a behavior tree node, but if that works for you then ok.
    2) disable AI motor control temporarily. You will probably want to create a custom motor for this that can deal with being deactivated/reactivated.
    3) remove rigid body constraints temporarily.
    4) apply the physics forces as in your example.
    5) once you are ready to return control to the AI, constrain the rigid body again and reactivate the motor

    This approach is similar to what we did with ZombiePlayground. In that game, low-level movement is actually controlled by a state machine that switches between physics/ragdoll and animated movement. AI is used to send movement requests to the low-level system, which can ignore them when physics are in effect.



    Thank you! You replied me in a very short time, and helped me a lot!!!

    I change the way doing physics on rigidbody, and it works!!!

    I set velocity on rigidbody by doing this:
    myRigidbody.velocity = -vector3.back * power
    (rather than addforce to ai’s rigidbody)

    I also set constraint in behavior tree to determine if ai is under attack.

    ai will execute the knock back SEQ which include animation, custom action, wait for timer and expression(gethit=false).

    ai can do its normal behavior.

    I think the reason addforce can’t be work is because that I didn’t give it correct direction, so it just generate force inside the ai body, then did’t make any effect to ai’s transform.

    I wish there were no more problems.

    Thanks, Prime.

    • This reply was modified 1 year, 7 months ago by  leochou.
Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.