Hello everyone, I have a scene with a player (capsule collider + rigidbody + camera + my movement script) and a cube (cube collider + rigidbody). Every time that the player walks and join a collision with the cube it bounces back if the cube doesn't have space to move in the direction that is being pushed Here is a video showing the bouncing (when i go back im not pressing any button, its just the bounce) I don't want this to happen, i just want that if the player is moving the cube and it has no space it just stops moving, that bouncing is annoying and i dont know how to remove it. Can someone help me? Tganks in advance guys.
Variables: Code (CSharp): public InputAction walkInput; https://prnt.sc/sbvxji public InputAction lookInput; https://prnt.sc/sbw16s public GameObject mainCamera; https://prnt.sc/sbvy26 public float minYAngle = -50.0f; public float maxYAngle = 50.0f; public float sensitivityX = 6.0f; public float sensitivityY = 3.0f; on Update: Code (CSharp): private void Update() { var lookValue = lookInput.ReadValue<Vector2>(); currentX += lookValue.x * sensitivityX; currentY -= lookValue.y * sensitivityY; currentY = Mathf.Clamp(currentY, minYAngle, maxYAngle); } Move function (called on FixedUpdate): Code (CSharp): void Move() { var moveInput = walkInput.ReadValue<Vector2>(); Vector3 forward = mainCamera.transform.forward; forward.y = 0; forward.Normalize(); Vector3 right = mainCamera.transform.right; right.y = 0; right.Normalize(); Vector3 moveDir = right * moveInput.x + forward * moveInput.y; moveDir.Normalize(); this.transform.position += moveDir * moveSpeed * Time.deltaTime; this.transform.rotation = Quaternion.Slerp(this.transform.rotation, Quaternion.LookRotation(forward), 0.2f); mainCamera.transform.rotation = Quaternion.Euler(currentY, currentX, 0); } I think im not missing anything (just pasted the important things related to movement because that script contains a lot of things related to grabbing objects)
I don't know if that'll solve your problem but I think you should change the rigidbody's transform instead of the gameobject's transform. The reason is that when you move the rigidbody, the transform is calculated after the next physics simulation step. https://docs.unity3d.com/ScriptReference/Rigidbody-position.html Let us know if that helped !