So I want to do something simple, this is for an AI script.
My logic:
Once my enemy’s sword collides with my Player I want it to apply damage.
It applies damage but only when I’m moving not when I’m standing in one spot.
Here is my script, it’s really really simple and I honestly do not know what is wrong.
using UnityEngine;
using System.Collections;
public class weaponHit : MonoBehaviour {
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
//Ignore collisions between the Enemy and his weapon just in case
Physics.IgnoreCollision(transform.root.collider,gameObject.collider,true);
}
void OnTriggerEnter(Collider col)
{
// if the collided object is the Player then applydamage.
if(col.gameObject.tag == "Player")
{
col.gameObject.SendMessage("damageHero",10);
}
}
}
It’s not an error per se but he only applies damage when my character is moving and he collides with it. If he is stationary then he does not apply damage.
Make sure if you realy hit the box trigger, scale the box if needed.
Make sure if the character “Player” as collider and tagged “Player”.
Use debug.Logs, or Prints to help you, and see if that part of code is working or not, I personally use many times.
a) Already scaled t but no go.
b) Player is named Player and is tagged Player as well
c) Used debug.log and it says its applying damage only when moving
Oooooooooooooooooooooooooooh so all I needed was to send that message to the collider and access the script on my player to do it correctly? I just want to understand what I did wrong. But honestly MANY MANY thanks for the fix
FIXED! my problem was that my enemy AI did not have a Rigidbody attatched and thus it was only applying the OnTriggerCalculation if the collider it was attacking was in movement. Setting a rigidbody fixed it