Hey,
I’m trying to make my character teleport a short distance. I want to make sure there are no obstacles in the new location with Physics.OverlapSphere. This works when the colliders actually Overlap, but when the character collider ends up inside another bigger collider, then the collision is not detected. Is this as intended, and if so is there some other way to detect collisions like this?
I suppose I could combine it with a raycast, but I would really like the player to be able to teleport over objects.
Explaining image:
The docs clearly state it should return all colliders overlapping or inside the sphere, so it’s probably your code. You are probably going to want to debug how you’re calculating the radius and position and debug that visually as well.
I use the non alloc version of this and my game would explode if it wasn’t working well. Perhaps it’s a bug in your version of Unity? in any case eliminate the possibility it’s your code first.
That’s what so strange. It should work.
Since the code works for when they actually overlap I thought there must be something else. I’ll try a different Unity version etc.
Thanks!
Don’t expect mesh colliders to give you good results unless they’re a) convex and b) have convex ticked as there’s no way they can figure out what is inside - obviously.
You considered that along with Getsize() providing correct results right?
Yes, I draw a Gizmo with that size at the targetposition. Looks correct.
Ah, that’s probably it, they are actually mesh colliders that are not convex! Will have to investigate that!
Thank you!
Edit: Non-convex mesh-collider was the problem! Works perfectly with a sphere collider.
Is there a way to mark answer as correct or something?
This is good advice to add to the docs really. I mean, it’s not something you consider first thing when working with Physx / Unity’s physics. Glad it fixed your problem!
You can optionally edit the topic title, but otherwise I don’t think there’s a marking system for that.
Hi, I am able to get the name of the objects which are there in the collider radius but wants to get the data of the objects which are there in the collider radius. for ex. every object has it’s serial number and data. How I can get those things.
Thanks
I know this thread is old, but is there a workaround to this issue? It’s not possible to use Convex colliders in my case. I just need to figure out whether a certain point is inside any object.
I’m also having an issue with Physics.OverlapSphere. In a webGL build Physics.OverlapSphere is not picking up my generated meshes. But everything works fine in the editor.
I described my problem a bit more here Issue with dynamically generated mesh detection in unity build . I’ve tried a few different things, but am pretty stuck with what to do next. Any help would be greatly appreciated. Thanks!