Rigidbody goes through an object
I have a player and it has attached a rigidbody. I use for a horizontal movement a MovePosition() function. But when I get to an object with the player and press keys to move it goes slightly through the object. Triggers are unchecked. I have already set rigidbody collision detection to Continous Dynamic, interpolate to extrapolate. But anyway a part of piece player goes slightly to the object. I would like to know if it is normal behaviour or which properties cause this problems of if there is any solution to avoid this issue.
There is moving script of the player: movingForward = Input.GetAxisRaw("Horizontal") * speed * Time.fixedDeltaTime; rb.MovePosition(new Vector3(0, transform.position.y, transform.position.z + movingForward));
I have a sneaky suspicion you might be moving your character through Update(). When moving your physics gameObjects with a rigidbody, use FixedUpdate().
Does the black box collider match its size? Can you link an image of the black one clicked?
Answer by Vega4Life · Dec 16, 2018 at 04:47 PM
After looking at your images and viewing your setup, this is a normal behavior against another gameObject that is static. Your situation becomes more problematic as the speed of the gameObject increases. Meaning - the more speed, the more it will penetrate.
I would assume as you hold the bottom down, it will stay penetrated. The second you release, it bounces back where you expect it to be. You are just fighting the physics solver. It is putting it back, but you just keep pushing it forward by the amount of movement forward applied.
As a not, you should use continuous here. Dynamic continuous is for rigidbodies hitting other rigidbodies. Continuous is for rigidbodies hitting statics.
Is there a way to solve this problem. Yes. You can lower the Fixed Timestep in the Time Manager. This will cost you CPU overhead.
Ok, I have set up the Fixed Timestep to 0.001 and change to CD - Continuous. It works much better but anyway smaller side of a player still goes to an object and it looks like the player is sticking on the object. https://imgur.com/a/ggQTjyy
I don't know why it's sticking like that. I don't think it's related to what we are touching. It could be a physics material on one of them?
So, I did suggest changing the Fixed Timestep, but let me explain what is actually happening here.
On your PC you are probably getting 60fps (unity uses the platforms defaults - 60 is pc). So that means, your getting a frame (1/60) around 0.016 a second or 16ms. Your default Timestep is 0.02 a second or 20ms. In this case, your physics update isn't one to one with your frames. Just going a little bit below 0.016 is probably all you need for Fixed (0.015ish).
With a 0.001 timestep, thats 1ms. At 16ms a frame, you are updating your physics around 16 times per frame. Yeah, you don't want that. Be careful when messing around with fixed timestep. :)
No, no there it is not any physics material and the Fixed Timestep works fine on 0.001. But thank you very much!
Your answer
Follow this Question
Related Questions
I want stop the rotation when the player run around 0 Answers
How to add gravity to imported objects? 1 Answer
Having a OnTriggerEnter make another gameobject Add Force in UnityScript. 1 Answer
How to set rigidbody velocity and angularVelocity to Vector3.zero over time? 1 Answer
Object shakes on collide! 1 Answer