Ginxxx
Ginxxx

Reputation: 1648

Infinite bouncing of ball (Unity)

I'm currently creating a simple game like the Angry Bird. So I succesfully created something like that and I'm currently facing a problem where in I want to shoot the bird infinitely like if it hits the wall it should just bounce back and if it hits a wall again it will bounce back like infinite.

Here's my shoot code

public float force = 1300;

private void OnMouseUp()
{
    // Disable IsKenematic
    GetComponent<Rigidbody2D>().isKinematic = false;

    // Add the Force
    Vector2 dir = startPos - (Vector2)transform.position;
    GetComponent<Rigidbody2D>().AddForce(dir * force);


    //Remove the script (not the gameobject)
    Destroy(this);

}

EDIT

Just to add an information I am using Physics 2D material Friction: 0.8 Bounciness: 0.45

Upvotes: 0

Views: 4445

Answers (3)

Ginxxx
Ginxxx

Reputation: 1648

Yehey thanks for the help guys finally able to control the ball by doing this setting on the rigidbody and physics 2d material

rigidbody drag all off gravity is zero

physics 2d material friction is 0 bounciness is 1

THANK YOU

Upvotes: 0

janavarro
janavarro

Reputation: 889

Set the Rigidbody.Drag of the game object to 0.

More info on what Drag does: https://docs.unity3d.com/ScriptReference/Rigidbody-drag.html

You should set the Rigidbody.GravityScale too to 0.

If you want to control the constant speed too change Rigidbody.Velocity.Magnitude.

Upvotes: 3

Jax297
Jax297

Reputation: 657

Originally answered HERE , you could use the suggested ZeroFriction material for walls, etc. I've used this in one previous attempt and it worked fine.

Upvotes: 0

Related Questions