2D game - Sprite deformation when add frce

Hi.

I created an image and added to it Collider, Rigidbody2D. Also I create script with function which called when pressing the space key and AddForce to this image. After when I start project and press Space key I saw that object start deformed. Whel it collision with other object Player very deformaed. It is deformed and stretched in width upwards. But when I set equal force for X and Y axis Player didn’t deformed. For example

transform.AddForce(500f, 3000f); // Deformed

transform.AddForce(3000f, 3000f);//  Not deformed

82097-1.png

Ball components

Ball script with AddForce

void Update () {
        if (Input.GetKeyDown(KeyCode.Space))
        {
            Debug.Log("Add force");
            GetComponent<Rigidbody2D>().AddForce(new Vector2(xForce, yForce));
        }
}

What do to fix this problem?

Can you please explain what you mean by ‘deformed’? Do you mean the scale changes? Adding a force or colliders contacting do not change the Transform scale so you must have some other script/animation doing that.

Adding a force only changes the velocity of a Rigidbody2D and nothing else.

Hi ! First of all you shouldn’t use GetComponent method each frame just to get the same rigidbody. This is very bad for performance.

private RigidBody2D rb;
void Start(){
     rb = GetComponent<RigidBody2D>();
}

 void Update () {
         if (Input.GetKeyDown(KeyCode.Space))
         {
             Debug.Log("Add force");
             rb.AddForce(new Vector2(xForce, yForce));
         }
 }

Also don’t use a Gravity scale of 110. That is very bad and can cause severe problem. This show a problem in your current hierarchy. Try to tweak the size of your game object instead of computing crazy Physics parameters.