- Home /
Question by
RandomnessThatsFunny · Sep 07, 2017 at 05:34 PM ·
c#collisiontriggertriggersweapon system
Trigger Collision Moves When Object Enters
I am working on a game and I'm coding in sword movement. I have it where if you swing your sword it has a trigger collision to check if anything is there. The problem is that when something enters that collision the collision moves under the player / moves out of the way.
I have been having this problem all day and I can't figure out a solution.
void animate(string _type)
{
switch (_type)
{
case "WAND":
weaponSpawn.transform.GetChild(0).GetComponent<Animation>().Play("Wand", PlayMode.StopAll);
GameObject projectile = Instantiate(wandBullet, hitSpawn.transform.position, hitSpawn.transform.rotation);
projectile.tag = "MyHurt";
projectile.GetComponent<Rigidbody>().AddForce(transform.forward * currentWeapon.speed);
projectile.GetComponent<BulletDamage>().damage = currentWeapon.damageAmount;
StartCoroutine(destroyProjectile(projectile));
break;
case "SWORD":
weaponSpawn.transform.GetChild(0).GetComponent<Animation>().Play("Sword", PlayMode.StopAll);
meleeHit.GetComponent<BulletDamage>().damage = currentWeapon.damageAmount;
StartCoroutine(turnOffMelee(currentWeapon.rate));
break;
}
}
IEnumerator turnOffMelee(float _time)
{
meleeHit.gameObject.GetComponent<BoxCollider>().enabled = true;
meleeHit.GetComponent<BulletDamage>().damage = currentWeapon.damageAmount;
yield return new WaitForSeconds(_time);
meleeHit.gameObject.GetComponent<BoxCollider>().enabled = false;
}
I can show you the full script and images if you need it.
Thanks,
Mark
Comment
Answer by Akusan · Sep 07, 2017 at 05:55 PM
Maybe your target has a rigid body and is getting pushed by your sword rigid body. Just add a larger trigger collider on your target or your sword and make the necessary scripts for reactions