Add force through animation event?

zoicelols

Member
Trying to add force to an attack animation through a custom event animation. I see someone posted about adding force through the locomotion script. Where would I be able to find information on where to add the force lines in code so that it works on my animation event? I found unity's and followed it, but it doesnt work. I used getcomponent rigidbody and such in a new seperate script and attached it to my character. Does the code need to inherit from somewhere?
 
You could create a script which listens for the animation event and then call the AddForce method on the CharacterLocomotion component.
 
How would I specify adding force to that script? Right now I know how to add force to the rigid body only.

This is what I was trying and I'm not sure how to specify for the locomotion script after get component instead of rigidbody.

I tried multiple different ways.



C#:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

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

    void Start()
    {
        rb = GetComponent<Rigidbody>();
    }
    public void ForceForwardEvent(string F)
    {
        rb.AddForce(0, 0, thrust, ForceMode.Impulse);
       
    }
   
   
 
}
 
Last edited:
Okay figured it out.


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);
        

    }
    
    
  
}
 
Top