Search Unity

how to keep an object moving even it collides some other object

Discussion in 'Physics' started by ahmetemre4235, Apr 29, 2020.

  1. ahmetemre4235

    ahmetemre4235

    Joined:
    Apr 10, 2020
    Posts:
    2
    Hey, i want the red ball to move forever in random directions and keep moving even it collides another object. But when it collides an object. it just stuck like that. I increased the bounciness but it didn't work. how can i solve this problem? Here are my scripts below

    here is the video: https://imgur.com/FueJAM9

    Code (CSharp):
    1. Rigidbody2D drb;
    2.     public float movespeed;
    3.    
    4.     private void Awake()
    5.     {
    6.         drb = gameObject.GetComponent<Rigidbody2D>();
    7.     }
    8.     void Start()
    9.     {
    10.         Vector3 rand = new Vector3(0, 0, Random.Range(-180f, 180f));
    11.         transform.Rotate(rand);
    12.     }
    13.  
    14.    
    15.     void Update()
    16.     {
    17.        
    18.     }
    19.     private void FixedUpdate()
    20.     {
    21.         move();
    22.     }
    23.     void move()
    24.     {
    25.         drb.velocity = transform.up * movespeed;
    26.     }