- Home /
Problem with pushing an object
Hey guys, I try to make a first person game where you can go and move objects. When you press the left mouse button i save the object that in front of me (in a range) into a variable. Now when i move i push the this object, moving the mouse up and down will make this object go up and down. The object will have no gravity at this time and fly in the air. If the first distance that the object was from the player is X then as long the mouse button is pressed the distance will try to be X as well in front of the player. This box (the one that i grab) has a rigid body. To move this box to the position I want, in front of the player I use rigidbody.MovePosition, this function supposed to move the object without collide it with others in the way. The problem is where there a wall. I can push this box in the air. How can i make sure that when i move a rigid body it doesn't pass through other objects? I understood that this function supposed to do that. In addition, I tried to change the velocity of this box and not the position. I can still push the box through walls. This time, before it pass the wall there is a lot of tiny jumps, A LOT. This is very ugly too. If i hold the box close enough then it won't pass through the walls but when I come close enough to the wall it will move like crazy. I don't know how to describe it but I think every unity user know that. It happen because my wall, player and the box are almost at the same place, they collide.
So my 2 questions are:
How can i make sure that when i move a rigid body it doesn't pass through other objects?
How can i disable that if the player hold the box close enough and go into a wall it move like crazy?
Thank you guys for your time :)
i had same problem, but i used simply any collider, i mean box sphere or any collider. and then problem solved
I find solving these problems is not a one-size-fits-all solution. I have to play with the situation until I have something that works the way I want. Three things to explore:
Take a look at the standard DragRigidbody.js script (Assets > Import Packages > Scripts). They use a spring joint at the point of dragging.
See if reducing the fixedTimestep improves the situation. as a start, go to Edit > Project Settings > Time and reduce the fixedTimestep from the default of 0.02 to 0.01. This will result in more frequent physics calculations.
Go to Edit > Project Settings > Physics and set the '$$anonymous$$in Penetration For Penalty' to 0.0.