How to fix the vibration while colliding?

Game Development Asked on January 13, 2021

I’m making a 2D platformer with Unity. My game has a problem:

The player vibrates when it collides with something. It seems like it’s spinning or flipping very quickly. I used transform.position in my code before but because of some kind of vibration I changed it to AddForce but still I have that problem.

Thank you in advance.

   using System.Collections;
   using System.Collections.Generic;
   using UnityEngine;
   using UnityEngine.InputSystem;

   public class PlayerController : MonoBehaviour
   [SerializeField] private float jumpSpeed;

    public float maxSpeed = 5f;
    public float maxAcceleration = 50f;
    public float maxDeceleration = 100f;

    [SerializeField] private LayerMask ground;
    private PlayerActionControls playerActionControls;
    private Rigidbody2D rb;
    private PolygonCollider2D pol;
    private Animator animator;
    private Vector2 movementInput;

    private void Awake()
        playerActionControls = new PlayerActionControls();
        rb = GetComponent<Rigidbody2D>();
        pol = GetComponent<PolygonCollider2D>();
        animator = GetComponent<Animator>();

    private void OnEnable()

    private void OnDisable()

    void Start()
        playerActionControls.Land.Jump.performed += ctx => Jump(ctx.ReadValue<float>());

    private void Jump(float val)
        if (val == 1 && IsGrounded())
            rb.AddForce(new Vector2(0, jumpSpeed), ForceMode2D.Impulse);

    private bool IsGrounded()

        Vector2 topLeftPoint = transform.position;
        topLeftPoint.x -= pol.bounds.extents.x;
        topLeftPoint.y += pol.bounds.extents.y;

        Vector2 bottomRightPoint = transform.position;
        bottomRightPoint.x += pol.bounds.extents.x;
        bottomRightPoint.y -= pol.bounds.extents.y;

        return Physics2D.OverlapArea(topLeftPoint, bottomRightPoint, ground);
    void FixedUpdate()
        Vector2 movementInput = playerActionControls.Land.Move.ReadValue<Vector2>();

        movementInput = Vector2.ClampMagnitude(movementInput, 1f);

        Vector2 DesiredVelocity = movementInput * maxSpeed;

        var scale = transform.localScale;
        if(scale.x * rb.velocity.x < 0) {
        scale.x *= -1;
        transform.localScale = scale;
    void AccelerateTo(Vector2 desiredVelocity) {
       var deltaV = desiredVelocity - rb.velocity;
       var acceleration = deltaV / Time.deltaTime;
       float limit = maxAcceleration;

    if (Vector3.Dot(rb.velocity, desiredVelocity) <= 0f) 
       limit = maxDeceleration;       
       acceleration = Vector2.ClampMagnitude(acceleration, limit);
       Vector2 force = rb.mass * acceleration;


One Answer

Your calling void AccelerateTo(Vector2 desiredVelocity) in your fixedUpdate().

You should not use Time.deltaTime in a fixedUpdate - you need to alter this code.

var acceleration = deltaV / Time.deltaTime;

When you use Time.DeltaTime in fixedUpdate you do not allow it to work properly. FixedUpdate has the frequency of the physics system and is called every fixed frame-rate frame.

Correct answer by Chris Norman on January 13, 2021

Add your own answers!

Related Questions

My GameObject keeps spawning when it shouldn’t

2  Asked on November 9, 2021 by michael-hampshire


Texture blends into one single color

1  Asked on November 9, 2021 by andrey-k


Player jitters when Jumping at object edges

1  Asked on November 9, 2021 by cgaudet


My bullets won’t bounce in Unity?

1  Asked on November 6, 2021 by kayra-yorulmaz


How to time draw images to the window in d3d8

0  Asked on November 2, 2021 by kite


Tank / turret animations

0  Asked on November 2, 2021 by lilkrit


Problems with recursive backtracking algorithm for a 3D maze

0  Asked on November 2, 2021 by janis-taranda


Add a sound to all the buttons in a project

3  Asked on November 2, 2021 by hamza-memon


Editing terrain in Blender

0  Asked on November 2, 2021


Ask a Question

Get help from others!

© 2022 All rights reserved. Sites we Love: PCI Database, MenuIva, UKBizDB, Menu Kuliner, Sharing RPP, SolveDir