I have a character with attack animations and i want the other objects to be affected by it when i swing the sword. I tried collision boxes and what not and it seems the collision box doesn’t follow the sword during the animation, it just stays in place.
So i guess im trying to find a way to apply the animation to the collision box.
So, this is what I came up with.
using UnityEngine;
using System.Collections;
public class RotateOnHit : MonoBehavior
{
private bool rotate = false;
private float triggered = 0.0f, currentTime, timer;
public void Start()
{
this.timer = 10.0f;
}
public void Update()
{
if(this.rotate) {
if(this.triggered == 0.0f) {
this.triggered = Time.deltaTime;
}
this.currentTime = Time.deltaTime;
if((this.currentTime - this.triggered) < timer) {
// Should perform a relative spin
transform.Rotate(Vector3.right * Time.deltaTime, Space.World);
} else {
this.rotate = false;
}
}
}
// This may not be the correct method name pretty sure it is though
public void OnCollisionEnter(Collider e)
{
if(e typeof GameObject) {
// I haven't worked with Unity in a while,
// So it may be a different object path
if(e.gameObject.tag == "sword") {
this.rotate = true;
}
}
}
}