- Home /
How not to penetrate the walls?
I use the following code to move my character
transform.position + = new Vector3 (x * Time.deltaTime, 0, y * Time.deltaTime);
However, if the crash barrier, will penetrate and bounce I studied 'Standard Assets Example Project' but no harvest
Answer by Olgo · Apr 15, 2015 at 07:36 PM
by editing the position of your character, that's all you're doing, changing his position without being cognizant of collisions.
Add a character controller and use the .Move() function to control your character. This will check for collisions and stop accordingly.
I tried this method, he can really move! But in addition to '.move', penetrate anything Given rigid body and gravity, will penetrate the terrain
I try to use the $$anonymous$$ove gravity, it appears that a temporary solution to the problem
Answer by Tim Jansen · Apr 15, 2015 at 07:43 PM
I don't know what your scene looks like, but a common problem is that the character is moving so fast, that the character moves past the wall in between two physics updates, so the character has past the wall before the next update. If that is the problem, making the wall (or otherwise the collider) thicker or limiting the speed of your character should solve the problem.
I do not know what to do to limiting But if the scene is always thick walls, it seems not nice
It must pretty fast for this to be a problem, so if the character is moving relatively slow, then this is not the problem. Have you checked that not only the character has an collider, but the wall as well and that "Is trigger" is unchecked on both of them?
Answer by VoidScreamer · Apr 15, 2015 at 09:22 PM
a common cause is that "Drag" property on your RigidBody is 0. so it bounces and slides indefinitely. try 1 or 2. since you don't use AddForce for moving you Object, it doesn't affect physics. with drag set to 1, it will stay still after a little Bounce.
Note : you need a non-kinematic rigidbody and a non-trigger Collider to avoid penetration.
I tried using AddForce or other things But more unpredictable physical phenomena will happen, I do not know how to solve For example Danfei or impact
I prefer translate over addforce for many movement purposes. anyway, the drag should be set about 1 for translate. note that if you set it 1 and use addforce, the object will not move due to very high drag.(needs about 50000000 force for just 50 mass units). so set it carefully
Your answer
Follow this Question
Related Questions
OnCollisionEnter not working 1 Answer
How can I limit the rotation on the Y axis so the player cant spin the camera 360 in an FPS game? 0 Answers
Two Basic Physic Questions (Gravity and Jumping) 1 Answer
How to trigger different animations depending on where a gameobject collides? 1 Answer
[C#] Jump on slopes 1 Answer