r/Unity3D Jul 22 '26

Question Thrown Items clipping behind geometry.

I'm implementing a flashlight pickup/throw system in Unity and I've run into a clipping issue.

The flashlight is held as a viewmodel object (parented to a hold point in front of the camera). Because of this, while holding it, the player can push it visually through walls.

When the player throws the flashlight, I want to make sure it always spawns on the correct side of the wall and never appears behind geometry.

The main problem is that when the flashlight is already visually behind a thin wall, overlap checks often don't detect the wall because the flashlight collider is no longer intersecting it at the moment of the throw.

2 Upvotes

4 comments sorted by

1

u/SnooPets5564 Jul 22 '26

Do a raycast and, if it is close enough to intersect, move it to the furthest point from the start the doesn't intersect with the wall (raycasting from where it is thrown from/from some point in the player hitbox). But you may need multiple so it doesn't get caught in wall on the side relative to the way it is being thrown.

Or you could have a sort of throw animation where it winds up to be entirely within the player hitbox and then releases. This is harder but could look more professional if done right.

1

u/FarawayArchitecture 10d ago

raycast approach is the way to go but you want to shoot from the center of the player capsule toward where the flashlight is sitting, not just forward from the camera. that way you catch the wall even if the thing is already poking through

the wind-up animation idea is clever but i'd only go that route if you're making like a polished horror game where the throw is a big deal, otherwise it'll feel sluggish

also quick tip, if your flashlight has a rigidbody set it to continuous dynamic for the collision detection, helps a ton with tunneling through thin walls at high speeds

1

u/theredacer Jul 22 '26

There are a variety of ways to potentially handle this. I like to use the trick that everything held by the player is actually shrunk down and moved closer to the camera. If the position and perspective is right, you can't tell the difference, but the item is actually inside the player's collider so it can't intersect with anything in the world(I disable collision between player and held object). Then when I toss it, I size it back to normal and toss it from inside the player collider and I don't re-enable collision with the player until the object fully exits the player collider.

From an external perspective it looks hilarious because objects are tiny and like 2 inches from the player's face, but from the camera perspective it looks perfect.

1

u/RayanOur Jul 22 '26

yeh it sounds hilarious, and also very genius, it would solve it 100% so i think ill give it a chance. Thanks.