- Home /
How to use RaycastHit2D for a 2D projectile?
I have a small, fast-moving 2D projectile that shoots from my player in the left and right direction. Due to the size and speed of the object, it can often pass through other game objects.
I found a few tutorials that go over this using Vector3's and mouse position; however, my game uses neither of those.
Can anyone help me set up a simple RaycastHit2D that I can use on this projectile object?
Answer by Vincent1236 · Feb 20, 2018 at 11:57 AM
Are you using RigidBody2D? If so before trying the raycast route, have you tried setting the Collision Detection mode to continuous and Interpolate mode To Interpolate on your RigidBody2D?
Answer by nkcowmaster · Feb 21, 2018 at 05:40 AM
That is what I am currently using, however, the issue still arises where the projectile will sometimes pass through collision. I see that Raycasting is the best method to solve this issue, so that is the method I am hoping to learn to implement in a 2D setting.
Your answer
Follow this Question
Related Questions
How do I get my character to shoot a projectile in the direction of the cursor? 1 Answer
Inconsistent Reflection/Ricochet of 2D Lines at Specific Angles via Raycasting and 2D Colliders 2 Answers
Projectile move towards mouse cursor 3 Answers
ball breaks through walls 1 Answer
2d side scroller projectile/firing weapon script help needed. 1 Answer