- Home /
Question by
ImmanuelUchennaBest · Feb 01, 2019 at 01:58 PM ·
c#animationtimeaddforceanimator controller
How to use addforce after animation?
I'm making a third person game and the player is allowed to pick up and throw a ball. The throwing animation is a trigger. The problem is that the force is added to the ball before the throwing animation finishes. Here is my script using UnityEngine; using System.Collections;
public class throwx : MonoBehaviour {
public Rigidbody rb;
public Transform t_Camera; // Drag&Drop your camera over here from the inspector.
private Vector3 v3_Force; // Force reference vector.
public float f_Multiplier; // A multiplier value if the force wouldn't be enough.
public GameObject carryact;
public Transform ball;
// Use this for initialization
void Start ()
{
}
// Update is called once per frame
void Update ()
{
if (Time.deltaTime == 0f)
return;
if(carryact.activeInHierarchy)
{
if (Input.GetMouseButtonDown(0))
{
v3_Force = t_Camera.forward;
ball.GetComponent<Rigidbody>().AddForce(v3_Force * f_Multiplier, ForceMode.Force);
transform.rotation = Quaternion.Euler(0,t_Camera.eulerAngles.y,0);
}
}
}
}
Comment
Best Answer
Answer by bpaynom · Feb 01, 2019 at 02:47 PM
You can use Animation events. Create one at the end of animation, then that event call the method you want to add the force.