Move an Object to a blank location

Hi All,

I was having a problem with this. I have 5 first person controller objects. I switch between them periodically. Everything is working great except at some points I want to have one object be automatically moved to the exact location as another object then offset it a little bit.

This works but If I have a wall or something on at the offset the object being moved is inserted into that wall or on the other side of the wall even though I have a mesh collider on the wall. How can I make it offset to a blank location.

I hope this question makes sense. Im am very new with unity and could not find a solution to this problem.

Darrell

If you’re moving an object by changing an object’s transform.position, it doesn’t pay attention to physics. If you want to offset from an object, I guess you’d have to do a Physics.Raycast from an object’s transform.position and find out if it hits anything within a certain distance. If it doesn’t, then you can place an object, and if it does, then try raycasting in a diferent direction.

Thanks. That worked. I didn’'t think about using the physics raycast.

I think that this way you can still end up with objects inside objects as casting a ray from the inside to the outside doesn’t give a hit?
(so you’d need to cast a ray two ways).

Also, if you are transported inside a huge collider no ray with reach any of the walls. Not sure if that’s applicable in your situation.

Why not use way points? It sounds like it would be easier for what you wish to accomplish