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 Lil_Rimmy333 · May 21, 2012 at 09:50 AM · collisionenemygundamage

Collision Damage

Hello everyone! I am rather new to Unity, and I have only made a few test games so far. One of them was Moon Machine and then the FPS tutorial, but that got messed up due to several file errors.

Anyway, I am working on a test game to show some people who I am working with, and I need it by Monday. (7 days) Now, I have been working rather well, I even thought I would have this simple test done in a day, but then I hit the same wall as always.

The bloody damage wall.

Ok, so I have followed MANY tutorials or looked through other questions and so far nothing has worked. I almost had it at one point, and then it started talking about raycast.

To sum it up, this test game is a really simple game, where zombies move towards the player, doing damage on collision. The player fires bullets (Already working) which, on collision, do damage.

So, I have tried many different ways, but I have failed every time. I don't have any scripts you guys (and girls!) can fix or help me with as almost every tutorial or question deals with them already having their own weapon system. My weapon system is simply:

"Left click" "Bullet fires" "Done"

I want it to:

"Left click" "Bullet fires" "Bullet collides" "Enemy takes damage" "Done"

My question is:

How can I make bullets and zombies do damage on collision?

Thanks for any help!

EDIT: I have been doing everything in JavaScript, so I would prefer if I could get any scripts in that format.

Comment
Add comment · Show 5
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 syclamoth · May 21, 2012 at 10:00 AM 1
Share

Don't use bullets, use raycasts. Unless your weapons are mostly bows and arrows? The 'bullet through paper' problem will be your biggest issue here. Just having bullets isn't enough- do the zombies have a 'health' attribute and associated behaviour?

avatar image 3D-Magic-VR · May 21, 2012 at 06:56 PM 0
Share

Hi there, I got a doubt, the bullets that mentioned before, have the collider(box, sphere or capsule) and the rigid-body component and set it like is kinematic?, because with this you can make an script that check if there's collision or not :-).

avatar image Lil_Rimmy333 · May 21, 2012 at 09:57 PM 0
Share

Ok, I'm decided. After using AsgerR's script and still not getting it to work, I think I'll learn how to use raycast. This collision is just getting too annoying. But I still need a collision for the zombies. Somehow, they have to chase and collide with the player. I think I can get them to chase, but this collision is still annoying me.

avatar image AsgerR · May 21, 2012 at 10:01 PM 0
Share

First off my example is c# and second, have you made sure to add a sphere collider or box collider to your player? And have you made sure to tick it as "Is Trigger"?

avatar image Lil_Rimmy333 · May 22, 2012 at 06:25 AM 0
Share

Ah! It's c#. $$anonymous$$aybe that's why it didn't work. ;) I'll go fix that now. $$anonymous$$y fault mate, my fault!

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by AsgerR · May 21, 2012 at 09:34 PM

As syclamoth says in his comment i would also use raycasts. But if you really want to use bullets, then i would suggest that you make some kind of health script or just make a reference to the script that holds the health.

 public int health = 100; //either do it like this and attach it to the player or create a reference to the health script
 public int damage = 10;
 
 void OnTriggerEnter(Collider Enter) {
     if(Enter.CompareTag("Zombie") {
         health -= damage;
     }
 }

You should be able to use the same method for the bullets. Hope this helps you somehow :)

Comment
Add comment · 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

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

8 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Damaging Enemy strangely not working. 0 Answers

Damage on prefab collision? 0 Answers

Damage on collision with player.. 1 Answer

Enemy deals damage to player on contact 2 Answers

How i make the player damage the enemy specific enemy he is colliding with 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