Hi, Im trying to implement a shield system for my project, the idea is that if the shield is being held up then it’ll block any incoming attacks.
Now, when the enemy is in range it’ll use a Raycast function to see if the player is in range and send a notification to damage him, here’s the code that makes that work:
var hit : RaycastHit;
if (Physics.Raycast (transform.position, transform.TransformDirection(Vector3.forward), hit))
Distance = hit.distance;
// Checks if the raycasted object is in the range of attack
if (Distance < AttackRange)
// Calls the function "Apply Damage" on the object that's being hit
hit.transform.SendMessage("ApplyDammage", attackDMG, SendMessageOptions.DontRequireReceiver);
What Im wondering is if there’s a way to effectively block this raycast if an object such as the shield is in the way.
I tried giving the shield a collision box to see if that would stop the damage notification from reaching the player but that didnt work.
Is there any way to make that work? I know that I can probably make a condition to stop the player from receiving damage when the shield is up but I still want him to get damaged if he’s hit on the back.