Knockback when damaged

RaeJjin0

Member
I would like to setup a knockback system, which would make the player or enemy getting pushed away from the opponent.
I've setup everything i wanted, but now the battles seems a little too... static if i can say. The opponents don't move even with root motion since they're colliding on each others, and i had the idea of making the knockback when i saw this video :


This is like the characters could be pushed away dynamically by each others when colliding with weapons, like you would push a cube by only walking onto it.
I know where to place the script, in the Character Health component at onDamage event, but i am struggling with writting the code...
Could someone who knows anything about C# help me doing it ? I wanted to play with the character's rigidbody, making it being -1 when damaged, but someone told me that TPC/UCC doesn't use the rigidbody system, so i really don't know how to code it, i am not good at scripting and i don't know how to use Opsive's huge libraries on the Api section so...
It is entirely my fault for being an ignorant, that's why i am asking for help while i keep searching for a solution on the other side x)
 
This will require scripting but I recommend looking at the ability system:


You'll want to create a new ability that plays when there is damage (sort of similar to the damage visualization ability, except more extreme).
 
I know that i should make it a new ability or use the event system, but what i am asking for sir is a little help for the script. Isn't it possible to get some help to do the script ? Because Opsive's library is so huge that i wouldn't know what namespaces i should use, or even how exactly i can script a knockback for characters since the only way i knew was to make velocity of rigidbody being -1, but Opsive doesn't use rigidbody... So i am completely lost. Could someone help me doing the script, please ?
 
I am not able to help create custom scripts but I recommend taking a look at the existing documentation/abilities and using that as a base. You can still add velocity to a character using CharacterLocomotion.AddForce.
 
Thanks to your hint using CharacterLocomotion.AddForce and some more researches, i managed to do it using this :

C#:
C#:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Opsive.UltimateCharacterController.Character.Abilities;
using Opsive.UltimateCharacterController.Character.Abilities.Items;
using Opsive.UltimateCharacterController.Game;
using Opsive.UltimateCharacterController.Events;
using Opsive.UltimateCharacterController.Input;
using Opsive.UltimateCharacterController.StateSystem;
using Opsive.UltimateCharacterController.Utility;
using Opsive.UltimateCharacterController.Character;

public class AddForceAnimationEvent : MonoBehaviour
{
    public float thrust;
    public UltimateCharacterLocomotion rb;

    void Start()
    {
        rb = GetComponent<UltimateCharacterLocomotion>();
    }

    public void ForceForwardEvent(string F)
    {
        rb.AddForce(transform.forward * thrust);
    }
}

This works like a charm, thank you for the tips Justin. I'll make a new topic for a last help and i'll stop bothering you, promises !
 
Last edited:
Thanks to your hint using CharacterLocomotion.AddForce and some more researches, i managed to do it using this :

C#:
C#:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Opsive.UltimateCharacterController.Character.Abilities;
using Opsive.UltimateCharacterController.Character.Abilities.Items;
using Opsive.UltimateCharacterController.Game;
using Opsive.UltimateCharacterController.Events;
using Opsive.UltimateCharacterController.Input;
using Opsive.UltimateCharacterController.StateSystem;
using Opsive.UltimateCharacterController.Utility;
using Opsive.UltimateCharacterController.Character;

public class AddForceAnimationEvent : MonoBehaviour
{
    public float thrust;
    public UltimateCharacterLocomotion rb;

    void Start()
    {
        rb = GetComponent<UltimateCharacterLocomotion>();
    }

    public void ForceForwardEvent(string F)
    {
        rb.AddForce(transform.forward * thrust);
    }
}

This works like a charm, thank you for the tips Justin. I'll make a new topic for a last help and i'll stop bothering you, promises !
How are you getting this to work. It looks like you are adding it to the character because you are getting the Locomotion script, but how are you calling the ForceForwardEvent? You are using MonoBehaviour so it doesn't seem to be an ability since the Ability derives from the Ability class.
 
Top