Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 Blightmare · Aug 16, 2014 at 10:06 PM · collisiongameobjectraycastcolliderbullet

Raycast from inside an object

I'm building the code for a gun right now and the code works fine as in it applies the appropriate damage to an enemy hit. What I'm considering doing though is giving certain weapons pierce the enemy and hit any behind it. My idea was to cast a ray out from the point that the first ray hit the enemy and check if it hit a different enemy.

My thing is the logic in my head is telling me that casting it from the hit spot would collide with the enemy I just shot and do additional damage to it instead of any enemies behind it. I suppose I could avoid that by moving the rays start point a little bit on the forward transform where I would cast it from there but I want to know is if the start point happens to be inside the enemy, will it still collide with the first enemy or will it not return a hit until it hits a new enemies collider (or any walls behind them)?

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
1
Best Answer

Answer by robertbu · Aug 16, 2014 at 10:18 PM

For 3D colliders, a raycast against the backside of any mesh will not record a hit. So if you were inside a sphere or a cube, your Raycast would not hit the object the start position was inside. But you have to be careful. Imagine an enemy with hands and arms. Say your hit point was a hand, and you moved the ray a bit inside the hand. It is possible for the new ray to travel out of the hand but hit the front side of the body or face of the same enemy.

A better solution is to use Physics.RaycastAll(). Not the hits are not guaranteed to be sorted when using RaycastAll(), so you need to process the hits to figure out the order of the hits.

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 Blightmare · Aug 16, 2014 at 10:30 PM 0
Share

I see what you mean about the body parts. That slipped my $$anonymous$$d because right now my enemies are all in the block in stage and nothing more than giant capsules. It wouldn't be a problem if I left the overall collider a capsule but there's a number of reasons why I wouldn't do that. I'll look into he raycastall. I want the pierce to be limited depending on the weapon (pierces once for assault rifle, 2 maybe 3 times for sniper, etc) so I am a bit worried about the return order though.

avatar image
0

Answer by Adam_Benko · Jun 25, 2021 at 12:17 PM

Spawn a cube with collider at the impact site. Move it in direction of the bullet. Use on trigger exit method to get the back side of character.

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Particular collider not working properly... 1 Answer

Why do Instantiated GameObjects Colliders only work on player i am controlling,nothing else? 2 Answers

Get an Object to Face/Move to RayCast Hit.point? 1 Answer

Collision issues with game object 1 Answer

Get the script instance associated with a collider 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