- Home /
Stop picked up object clipping through walls?
To stop the object going through walls, I put it at the end of a ray if it's not hitting anything, and put it at the hitpoint if it is.
The problem is that is uses the object's transform.position, which is the center point normally, so half the object will clip through the wall.
What's the best way to make the object never go through?
For rendering purposes you can use layered cameras:
One camera renders only the pickups and the other renders everything else, so the pickups always appear to be drawn over the rest of the geometry if you give the pickups camera a higher layer.
For real non-clipping objects you can use the raycast you're using, but ins$$anonymous$$d make sure you place the object at the hit point, but at a distance that equals half the width/depth of the object's bounding box.
The bounding box thing will work unless the object is an irregular shape.
True.
Perhaps a rigidbody with mesh collider and using `SweepTest` will yield better results.
The bounding box thing will work even if it's an irregular shape- you don't want even a small part of the object clipping, so it's best to play it safe.
Your answer
Follow this Question
Related Questions
Raycast stops working after ~40 seconds when target has Rigidbody 2 Answers
Make a rolling ball always on ground without falling when reaching the edges of the map 1 Answer
Held cube clips through wall 0 Answers
Raycast doesnt detect object in front of rigidbody (player is stuck on wall) 1 Answer
Best way to shoot physical bullets? 2 Answers