Object shakes on collide!
void FixedUpdate() {
if (Input.GetKey(KeyCode.A))
transform.position -= cameraTransform.right * (Time.deltaTime * speed);
if (Input.GetKey(KeyCode.W))
transform.position += cameraTransform.forward * (Time.deltaTime * speed);
if (Input.GetKey(KeyCode.S))
transform.position -= cameraTransform.forward * (Time.deltaTime * speed);
if (Input.GetKey(KeyCode.D))
transform.position += cameraTransform.right * (Time.deltaTime * speed);
Hello, this is my player movement code. Problem is whenever I collide with something (I am using box collider), my object (player) shakes and sometimes falls off (not through floor).
I searched for it and somebody had the exactly same problem. Answer said use FixedUpdate() and don't use transform.Translate... I wasn't doing any of that.
Sorry for my English if I did any mistakes, thanks for any answer.
Edit: I have a not permanent solution: In rigidbody increase the mass.
Answer by Davinder_Singh · Jun 13, 2017 at 06:47 AM
I only know the problem which is I think you are using rigidbody and collider both with your object which generally makes objects to shake when you are using code like:
transform.position -= cameraTransform.forward (Time.deltaTime speed);
Solution of your question is you need to change the way of moving your player(don't use transform.translate either). Because this way of moving forces the object to move from one place to another.
Please tell me when you get solution.
Sorry for improper answer.
Thanks in Advance
transform.Translate doesn't work with my line (or I didn't write it right). Is there another translate method? I don't have any solution yet but I am doing several tests.
set my players rigidbody mass to bigger than the cube (collide test). And the one with bigger mass doesn't fall. If you set the cube's mass to bigger than player's mass, then it falls.
wonder if there is a thing to do with box colliders size. You know, the bigger surface you have, stronger force you give to terrain. So you don't fall (in real life of course). I increased my X and Z sizes to bigger than Y. And did the first test: Nothing changed...
I hope you understand me so according to that two factors, maybe we can find a solution. Thanks for your advices btw.