Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by ZegTronic · Dec 06, 2014 at 08:58 PM · c#collisionplayer

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.

Comment
Add comment · Show 3
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image ahmedbenlakhdhar · Dec 06, 2014 at 09:47 PM 0
Share

Is the weapon damaging your player? or the weapon is taking damage with your player?

avatar image Mmmpies · Dec 06, 2014 at 09:49 PM 0
Share

What scripts do you have attached to the sword and are the variable names the same?

avatar image ZegTronic · Dec 06, 2014 at 10:50 PM 0
Share

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.

1 Reply

· Add your reply
  • Sort: 
avatar image
1

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
 }

Comment
Add comment · Show 5 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image ZegTronic · Dec 08, 2014 at 01:19 AM 0
Share

What script would I put this on?

avatar image glitchs2d · Dec 08, 2014 at 01:33 AM 0
Share

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.

avatar image ZegTronic · Dec 08, 2014 at 01:51 AM 0
Share

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

avatar image glitchs2d · Dec 08, 2014 at 02:31 AM 0
Share

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.

avatar image ZegTronic · Dec 08, 2014 at 02:48 AM 1
Share

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

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges