Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 coe720 · Nov 22, 2016 at 09:06 AM · collidersphysics2dcollider2d

How do you keep a shot moving in the same direction/velocity after it has hit a target while allowing targets to bounce off of obstacles?

I have a shot that gets fired from a turret which needs to be able to hit multiple targets (once it hits one target the target disappears and the shot should continue in the same direction with the same velocity and can continue on and hit others). My issue is that the targets I currently have are triggers which can run into obstacles, but since they are triggers they simply pass through these obstacles. If I remove the trigger then they correctly run into and bounce off of obstacles but then the shot bounces off of them after hitting them rather than continuing through. So my question is how do I allow shots to hit targets and continue through them after hit while allowing targets to hit and bounce off of obstacles?

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

3 Replies

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

Answer by coe720 · Nov 23, 2016 at 07:32 AM

Thanks for the answers you guys, that definitely helped me go in the right direction. I ended up using Physics2D.OverlapCircleAll with the origin point being the center of my shot which returns a list of 2D Colliders that the circle encounters. Then I check the tag of each game object in that list to see if it's an actual target as opposed to an obstacle.

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
avatar image
0

Answer by NotEnoughLemons3D · Nov 22, 2016 at 07:18 PM

Check out Physics.RaycastAll

https://docs.unity3d.com/ScriptReference/Physics.RaycastAll.html

You can specify the distance of the Raycast and it basically sends out an imaginary line from a start point to a specified direction returning all of the objects it encounters. This way you can leave isTrigger toggled off and still detect all objects within the firing direction.

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 NotEnoughLemons3D · Nov 22, 2016 at 07:19 PM 0
Share

If you are using 2D you need to check out Physics2D's version.

https://docs.unity3d.com/ScriptReference/Physics2D.RaycastAll.html

avatar image
0

Answer by hexagonius · Nov 22, 2016 at 09:57 PM

what you could try is using the following trick. save the current velocity during each FixedUpdate step in the shot. OnCollisionEnter, handle your logic, use Phusics.IgnoreCollision to explicitly ignore any further collision with bullet and target and reapply the saved velocity. this way the bullet keeps moving while the target should bounce off.

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

CircleCollider2D vs PolygonCollider2D: which collision solving is less expensive? 1 Answer

How to add colliders as objects into a public variable in the inspector? 1 Answer

overlayCircle not working 1 Answer

Detecting top most UI element using Collider2D 0 Answers

Physics2D.OverlapArea inaccurate? 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