This is the code I'm using to make an object bounce across the scene:
using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using Random = UnityEngine.Random; public class Enemy2 : MonoBehaviour { [SerializeField] private float _speed; private Rigidbody2D _rb; private Vector2 _velocity; private void Awake() { _rb = GetComponent<Rigidbody2D>(); } // Start is called before the first frame update void Start() { Vector2 dir = Random.insideUnitCircle; if (_rb.velocity.x == 0 && _rb.velocity.y == 0) dir = new Vector2(0.5f,0.5f); _velocity = dir.normalized * _speed; _velocity = new Vector2(0, -1); _rb.velocity = _velocity; FaceDirection(); } private void FixedUpdate() { } // Update is called once per frame private void OnCollisionEnter2D(Collision2D other) { Debug.Log("Collision: "+_rb.velocity); _velocity = new Vector2(0, +1);//Vector2.Reflect(_velocity, other.contacts[0].normal); _rb.velocity = _velocity; } private void FaceDirection() { transform.localScale = new Vector2(Mathf.Sign(_velocity.x),1); } } I have hardcoded the initial and Reflect directions just to make sure it wasn't my fault and it produces same behaviour: The object gets stuck when colliders with a collider instead of "rebound".
I'm using a dynamic rigid body with trigger set to false and no linear drag.
Can anybody guess what's hapenning here?