• 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 Uriel_96 · Mar 14, 2011 at 02:52 AM · javascriptcollisiontagfind

Substitute of collision

My game is FPS style game and I don't want to use collision for the bullet detection of enemy so I want to know a substitute of this script but without using a collision system:

function OnCollisionEnter(other : Collision){
if(other.transform.tag == "enemy"){
//Do something
}
}

Note: Maybe there are many ways to do it, I actually know some ways to do it, but the important thing here is find the object where it pass(e.g. other.transform.tag == "enemy" that means it do something only if the object tag is equal to enemy)


Know I try it with Raycast, not error but when I quit the collider it doesn't work, it seams Raycast only works for using collider. This is the script I use:

//this script is in the bullet
var moredamage = 1.0;
function Update(){
var hit : RaycastHit;
if(Physics.Raycast(transform.position,transform.forward,hit)){
if(hit.transform.tag == "enemy"){
Debug.Log("You shoot me");
hit.transform.SendMessage("CanDie",moredamage,SendMessageOptions.DontRequireReceiver);
}
}
}

any suggestion, comment or answer would be great.

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

2 Replies

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

Answer by AngryOldMan · Mar 14, 2011 at 03:14 AM

Use raycasting, it still uses a form of collision but not the same as a collider colliding with another collider at runtime. search unity3d raycast tutorial in google, there are plenty of useful results there too many to list here.

Comment
Add comment · Show 7 · 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 Uriel_96 · Mar 14, 2011 at 03:43 AM 0
Share

thanks, I already know about raycast but, it can be possible to ins$$anonymous$$d of layermask use tag?

avatar image AngryOldMan · Mar 14, 2011 at 12:13 PM 1
Share

better take a look around the web and find out http://forum.unity3d.com/threads/28962-Identifying-GameObject.Tag-through-raycasting here is somewhere to get you started, check out some answers tagged raycast and tag on this website also.

avatar image Uriel_96 · Mar 15, 2011 at 01:41 AM 0
Share

but it seams something happens, again I don't know why it doesn't work without having a collider any suggestion or answer that could me with this please?

avatar image Bunny83 · Mar 29, 2011 at 02:25 PM 1
Share

Raycasts only can detect colliders. agains what you want to raycast? The visual $$anonymous$$esh is just visual. You have to use a collider to raycast against. Why don't you want to use a collider? you can mark the collider as trigger and you still can raycast it. A trigger don't disturb the physics.

avatar image AngryOldMan · Apr 03, 2011 at 03:48 PM 1
Share

He says "use primitives for colliders" not "dont use colliders!" The guy asking the question states that he is using a $$anonymous$$ESH collider. The guy answering states to use PRI$$anonymous$$ITIVE colliders (which is just the basic collider shapes like cube, sphere, etc) On another note just because someone says to do so in another post and it worked for that guy doesn't necessarily mean that is going to work for you. Alot of the question (the well asked and answered ones anyway) are specific to the questioner, most answers you will have to use as a GUIDE to help you solve your problems

Show more comments
avatar image
0

Answer by Noah-1 · Mar 14, 2011 at 03:40 AM

I reccomend you OnTriggerEnter:

function OnTriggerEnter (other : Collider){

if(other.transform.tag == "enemy"){

//Do something

} }

Check the box of trigger on the collider of your tagged Object.

Check this for more info

Comment
Add comment · Show 1 · 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 Uriel_96 · Mar 14, 2011 at 03:48 AM 0
Share

sorry, but what I actually want is don't have a collider on, I forgot to mention it :P

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

No one has followed this question yet.

Related Questions

How to find layer instead of tags 3 Answers

Can someone help me fix my Javascript for Flickering Light? 6 Answers

Setting Scroll View Width GUILayout 1 Answer

Find children by tag from Player 1 Answer

How to find a prefab in another scene? 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