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 TheShadyColombian · Oct 27, 2014 at 01:36 AM · collidertrigger

How to make an enemy recognize a bullet

i have tried to make a trigger collider around the enemy, but it won't always recognize the bullet. how else can i do this?

Comment
Add comment · Show 4
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 JSierraAKAMC · Oct 27, 2014 at 01:53 AM 0
Share

Because colliders sometimes won't recognize collisions at high speeds, it's better to use Raycasting. Some info about Raycasting is here:http://docs.unity3d.com/ScriptReference/Physics.Raycast.html Best of luck. Feel free to ask any questions about Raycasting if you decide to use it.

avatar image robertbu · Oct 27, 2014 at 04:32 AM 0
Share

http://wiki.unity3d.com/index.php?title=DontGoThroughThings

avatar image TheShadyColombian · Oct 27, 2014 at 12:35 PM 0
Share

i tried that too, but i'm pretty sure recasts return a boolean of wether there is something in front of it or not. i need the script to know the specific game object so that i will damage that enemy, not some random one.

avatar image ABerlemont · Oct 27, 2014 at 01:27 PM 0
Share

You can retrieve whatever object was touched by the raycast

http://docs.unity3d.com/ScriptReference/RaycastHit.html

RaycastHit hit; if (Physics.Raycast(transform.position, -Vector3.up, out hit, 100.0F)){ hit.collider }

1 Reply

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by MrSoad · Oct 27, 2014 at 01:30 PM

Do something like this for finding out which object you have hit, read the comments as this won't just cut and paste due to the raycast parameters used in this example.

 function subDetect_Bullet_Hit() {
 
     var hit : RaycastHit;
     var oOther_Object : GameObject;
     
     //These parameters are from something I did, not instantly transferable to your project and needs
     if (Physics.Raycast (transform.position, transform.forward, hit, fRaycast_Distance, lmPlayer)) {
         
         if (hit.collider.gameObject.tag == "Your_Target_Object_Tag") {
         
             //Do you what you want now you know it has hit what you want.
             
             //You can store this gameobject, find its components and scripts etc,
             //and do whatever you need with it, inc destroy it.
             //Store like this :
             oOther_Object = hit.collider.gameObject;
         }
     }
 }

Comment
Add comment · Show 17 · 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 TheShadyColombian · Oct 28, 2014 at 05:13 PM 0
Share

can you show me this in C#?

avatar image fafase · Oct 28, 2014 at 05:14 PM 0
Share

Can't you try yourself? Would be a little bit of learning.

avatar image TheShadyColombian · Oct 28, 2014 at 05:17 PM 0
Share

alright, i'll give it a shot

avatar image TheShadyColombian · Nov 01, 2014 at 02:35 AM 0
Share

it doesn't seem to work. is there an option for debug that visually shows me the raycast? it'd be really handy

avatar image TheShadyColombian · Nov 04, 2014 at 09:15 PM 0
Share

Thanks dude! sorry it took so long to accept your answer, but i had to tweak it a lot to get it to work

Show more comments

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

29 People are following this question.

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

Related Questions

Can't click gameobject when over another trigger? 1 Answer

Something wrong with destroying script 0 Answers

Problem with the collider(I think) 0 Answers

How having correct bounce on a rotating pinwheel(it's more complicated)? 0 Answers

Enable objects to enter the trigger 2 Answers


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