private void OnCollisionEnter2D(Collision2D other) { if (!isPlayer) { return; } if (other.gameObject.tag == "Knife") { StopPlayerMovement(); m_rigidbody2D.AddForce(PhysicsUtils.GetRandomForce(32f, 32f), ForceMode2D.Impulse); m_rigidbody2D.gravityScale = 1; onCollisionKnife?.Invoke(); } else if (other.gameObject.tag == "Wood") { m_rigidbody2D.velocity = Vector2.zero; m_rigidbody2D.bodyType = RigidbodyType2D.Kinematic; StopPlayerMovement(); gameObject.transform.parent = other.transform.parent; onCollisionWood?.Invoke(); } }
public void TestRangeForce() { // Use the Assert class to test conditions Assert.Less(Mathf.Abs(PhysicsUtils.GetRandomForce(16f, 32f).x), 32f); Assert.GreaterOrEqual(Mathf.Abs(PhysicsUtils.GetRandomForce(16f, 32f).x), 16f); }