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 Serge144 · Jun 27, 2018 at 12:58 PM · collisionraycastraycastingbulletraycasthit

Raycast bullet collision problem

So i have been developing this classic game for training where the player is shooting bullets to some weirdly-shaped enemies. Initially, i had the very common problem of bullets going way too fast through some collider which is not triggered when the bullet passes through it (this target is not solid). So i implemented the raycast test which basically creates a raycast between the position of the bullet in the current frame, and the position of bullet in the previous frame, checking for collision hits. This step worked fine, but raycast lead me to another problem: The edges/borders of this target ARE solid (just like a ring or torus, if the bullet collides with the borders then the bullet may ricochet in or out of target area). So, if the bullet ricochets OUT of the target area, the constantly-moving ring may still catch up with the previous position of the bullet when it ricochet. In other words, suppose frame A is exactly when the bullet collides with the ring border at position P, the next frame B the bullet is ricochet out of the ring and not in touch with the borders anymore, meanwhile the ring target area has moved into position P, therefore raycast hit between frames A and B will find a collission.

How can i overcome this problem? Hope i made myself clear, Thank you in advance

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Glurth · Jun 27, 2018 at 03:04 PM

"bullet in the current frame, and the position of bullet in the previous frame"
" the bullet may ricochet "

I believe this combination may be a part of your troubles. Consider; if the bullet hits the border and ricochets at a time that is halfway between two frames. In this case, the line between the bullet position, in each frame will NOT include the target.

I would suggest you leave everything in the "current" frame; Compute the bullets position, assuming it moves in a straight line, at the end of the frame yourself, the formula for that is simply: (position + (velocity*frametime))

Use that as your final point for the raycast, (and current position as raycast start), and check the raycasts against the current position of objects in the scene.

Alternatively, you can COMPUTE the bullets last-frame position, using the same method. (again the advantage to computing over recording it, is you know you are computing a straight line, with no bounce.)

Comment
Add comment · Show 3 · 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 Serge144 · Jun 27, 2018 at 04:08 PM 0
Share

I think i understand, so basically i need to calculate where the bullet is going to be in the next frame and then raycast between that calculated point and current point of the bullet. But what if it ricochets? how do you calculate that.

avatar image Glurth Serge144 · Jun 27, 2018 at 04:27 PM 0
Share

"how do you calculate that." You just check for an affirmative return when you test your raycast. If you get one, it should ricochet. Oh, are you asking how to compute the position of the bullet after the ricochet? That is tricky when using rigid bodies, better to let the physics system do that itself. Better to adjust the collision mode for the objects to CollisionDetection$$anonymous$$ode.ContinuousDynamic or if necessary, use the rigid body interpolation member (https://docs.unity3d.com/ScriptReference/Rigidbody-interpolation.html). I should have mentioned those first actually, as they may eli$$anonymous$$ate the need for the raycasting at all.

avatar image Serge144 Glurth · Jun 27, 2018 at 07:54 PM 0
Share

hmmm thanks for the fast response. Like... this is similar to a classic bullet game where the player shoots bullets to weirdly-shaped moving enimies.. I believe it's not quite the resolution that im looking for because i have other factors in the game. Thanks either way!

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

171 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 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 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 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 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 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

Raycast Not Drawing In Target Direction 0 Answers

Raycast goes through 1 Answer

How do I check for collisions when I move objects based on Time.deltaTime? 3 Answers

Using Raycast Normal to match surface rotation to instantiated gameobject? EXAMPLE GIF Included 0 Answers

Detect RaycastHit on Character Controller 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