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 Kacer · May 04, 2011 at 07:17 AM · raycastcollidernameignore

Raycasts ignoring colliders based on Collider Name

Hello

I have a small problem with a FPS game im making currently, the issue is, if i fire at a too low angle i will hit my own collider, and therefore kill myself, now this is certainly not intentional and i've been trying to find various ways to fix it.

What i want to do, is to have the ray ignore the collider on the player, your own collider. This can be easily solved by using a layer. But, the prefab that you use gets instantiated whenever a player joins, so if i put my own player on a "ignore raycast" layer, the other players will be ignored as well.

I have tried using a if-sentence to stop the ray from killing myself, but as i have hit a collider the ray wont continue.

What i think would work, was if i could ignore colliders based on their name, since the name of the prefab gets randomized for every player that joins. Any ideas on how to do this?

Edit/Update:

I seem to have figured out how to fix my issue, what i am going to do is to limit the maximum amount of players on the server at a time to 16. Then when a player joins, he is put onto a layer of his own, which will then be ignored by him, and him only.

The only problem i have with this, is that i have no idea how to fetch/make an ID based on the player who joins, im looking for a single/double-digit integer which i can use to assign a layer to a player.

I hope someone can help me with this :)

Thanks in advance

Seth

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 Eric5h5 · May 05, 2011 at 10:04 AM 0
Share

It would be simpler if you started the raycast outside the collider. Then you wouldn't have to worry about hitting it.

avatar image Kacer · May 05, 2011 at 10:40 AM 0
Share

Doesnt the raycast begin at the camera's near surface?

It does indeed sound like a solution, but im unsure about how to implement it :)

avatar image Kacer · May 05, 2011 at 10:41 AM 0
Share

perhaps i should check up with the documentation before commenting, derp, i'll look into it.

2 Replies

· Add your reply
  • Sort: 
avatar image
2

Answer by Meltdown · May 04, 2011 at 07:40 AM

Take a look at giving your GameObjects a tag

So give your player his own tag, and the other players another tag..

Then do something like

if (other.gameObject.tag == "MyPlayer") 
// Ignore raycast here
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 Kacer · May 04, 2011 at 08:04 AM 0
Share

but my own collider will still stop the ray, no?

avatar image
0

Answer by Chiroculon · Apr 06, 2017 at 10:04 PM

@Kacer The solution is to use the physics engine's layers system and then tell the raycast to only collide with the specific layers that you need it to.

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

1 Person is following this question.

avatar image

Related Questions

Just wondering how I can create a child for each generated hex and make that child a sphere collider? Thanks. 2 Answers

Make raycast ignore some objects. 2 Answers

Raycast with doubleCollider 3 Answers

raycast not colliding 1 Answer

Checking raycast hit on tagged collider- "Cannot implicitly convert type 'string' to 'bool'" 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