0
\$\begingroup\$

So, I just realized, an image with BoxCollider2D wont detect any collision with Sphere with SphereCollider.

I tried adding a BoxCollider to my image, but it behaves in a weird manner (The Canvas position keeps shifting)

So, I can see the only way for it to work is adding a 2D Collider to the sphere? Is there any other better way to solve it? Adding a 2D Collider to the sphere wont cover the whole area

\$\endgroup\$
  • \$\begingroup\$ A SphereCollider is a 3D object, handled by Unity's 3D physics engine, PhysX. A BoxCollider2D is a 2D physics object, handled by Unity's 2D physics engine, Box2D. These are two separate worlds that don't interact. What exactly is your expected behaviour for collisions between these two objects, and how do your results so far differ from what you want? (ie. what specifically is "weird" about the way the canvas position shifts in response to collisions?) The more precisely you can describe your problem and what you want, the better we can help you solve it. \$\endgroup\$ – DMGregory Jul 14 at 11:45
  • \$\begingroup\$ @DMGregory So, this is a VR application. My image is a reticule. The image is directed by my head movement. So, I want to trigger a function when my reticule touches the sphere. The problem here is, the Canvas floats towards the camera every time. \$\endgroup\$ – MrRobot9 Jul 14 at 20:36
  • \$\begingroup\$ @DMGregory The reticule is supposed to be 4 units apart from the camera (head). As soon as I disable the BoxCollider from the image, the Canvas stops floating towards the Camera, and behaves the correct way. \$\endgroup\$ – MrRobot9 Jul 14 at 20:37
  • \$\begingroup\$ It sounds like what you really want here is a spherecast or boxcast query along the line of sight, not a collision response. \$\endgroup\$ – DMGregory Jul 14 at 21:14
  • \$\begingroup\$ @DMGregory So, should I remove the box collider from the image? and I have 4 spheres in the scene, so I should check which collider my spherecast is hitting in the Update function? \$\endgroup\$ – MrRobot9 Jul 14 at 21:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.