- Home /
picked up objects go through walls
Hello so i have the player able to pick up a cube. But when the player goes to the wall the cube docent stop at the wall it just goes through. I want the cube to stop at the wall. the cube for moving the cube to the player is:
` rigid.transform.localScale = Vector3(1,1,1);
rigid.renderer.material = Capture;
rigid.rigidbody.useGravity = false;
rigid.MovePosition(transform.position + transform.forward * holdDistance);`
Have you tried moving it differently? (force, for example) I have never used http://docs.unity3d.com/Documentation/ScriptReference/Rigidbody.$$anonymous$$ovePosition.html but I have a feeling that you're simply setting the cubes position which is the reason why it goes through the wall.
I don't know why I laughed so hard at "the cube for moving the cube to the player"
Answer by Croser · Sep 16, 2013 at 11:56 PM
Put another camera as a child of the main camera.Make a new layer. Set the child cam's culling mask to that new layer. Set the depth of the child camera to 1 and Clear Flags to 'Don't Clear'. Then, once picked, change the picked objects layer to the one you made the child camera see.
Here's what the function in my 'Pick_Me_Up_Bro.js' looks like.
function PickMeUp(){
transform.parent = PageHolder;
transform.position = PageHolder.position;
transform.rotation = PageHolder.rotation;
//Here's the layer changing line.
transform.gameObject.layer = LayerMask.NameToLayer("Pages");
Picked = true;
if(EventActivator){
EventHolder.active = true;
}
}
I know how to make the object visible through walls but this doesn't do what i want i want it so stay behind the wall not go through and still be able to see it.
In that case you could use Lerp to keep the object in desired position, if I'm not mistaken this should also prevent it from going trough walls and stuff.
Something like this.
transform.position = Vector3.Lerp(transform.position, target.position, delay);
Your answer
![](https://koobas.hobune.stream/wayback/20220613114313im_/https://answers.unity.com/themes/thub/images/avi.jpg)