- Home /
My weapon takes damage. help...
In my game I can take damage from an enemy sword, but so can my sword because it's attached to my player. I can't take it off my player in the Hierarchy because then it wont follow where I look. How would I go about not taking damage from my sword?
Here's my Player's code for colliding with the enemy sword:
private bool yesHurtMe = true;
void OnTriggerEnter(Collider other){
if (other.name == "Enemy Sword" && yesHurtMe == true){
will -= 20;
yesHurtMe = false;
}
}
void OnTriggerExit(Collider other){
if (other.name == "Enemy Sword" && yesHurtMe == false){
yesHurtMe = true;
}
will is my Health.
Is the weapon damaging your player? or the weapon is taking damage with your player?
What scripts do you have attached to the sword and are the variable names the same?
the weapon is taking damage with my player, and I have one script on the sword that makes it when i swing, if I hit something, it does damage, but the enemy's script allows it to deal the damage.
Answer by glitchs2d · Dec 06, 2014 at 11:18 PM
Since the weapon is attached to the player, do a check with the collider to ensure its not detecting the contact with it's parent. Something like
if(other.transform != this.transform.parent)
{
// Attack Code here
}
I'm not 100% sure of what you are asking but if you change your if statement to
if
(other.name == "Enemy Sword" && yesHurt$$anonymous$$e == false && other.transform != this.transform.parent){
yesHurt$$anonymous$$e = true;
}
it should work.
sorry, but if you clarify what you think my problem is, I can tell you what's actually wrong, I'm terrible at explaining things, basically, this is the code for my player, so adding parent doesn't do anything. Whenever my player(which includes all my objects + my sword) touches the enemy's sword, my player takes damage
thank-you
Ok well that changes the part to other.transform.parent != this.transform
This will hopefully work as long as the weapon itself is actually a child of the player.
I'm probably just REALLY bad at explaining things, it didn't work, but it's ok, because while I was waiting for your reply, I thought up of a game mechanic that will take use in this
thank-you for trying :)
P.S. and the sword is actually a child of the camera which is a child of the head which is the child of the player... (which may have complicated things..)sorry lol
Your answer
Follow this Question
Related Questions
Checking collision between 2 objects on 3rd object 0 Answers
Remove objects if 3 or more of them are colliding 0 Answers
When player hit wall continue moving 0 Answers
Issue with GameObject has been destroyed but it is not destroyed 1 Answer
Collision If Statement And Falling throught the ground (2 questions) 1 Answer