From 17c35b411eee6b7086bb1176e92bec75cb67bc7d Mon Sep 17 00:00:00 2001 From: allylikesfrogs Date: Thu, 4 May 2023 13:31:41 -0700 Subject: [PATCH] boing boing mf --- Assets/Scripts/BounceBehavior.cs | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/Assets/Scripts/BounceBehavior.cs b/Assets/Scripts/BounceBehavior.cs index 08b9007..074b542 100644 --- a/Assets/Scripts/BounceBehavior.cs +++ b/Assets/Scripts/BounceBehavior.cs @@ -4,15 +4,18 @@ using UnityEngine; public class WaterBehavior : MonoBehaviour { - // Start is called before the first frame update - void Start() + public Rigidbody2D RB; + + [SerializeField] private float bounceForce = 2; + + void OnCollisionEnter2D(Collision2D col) { - + Bounce(); } - // Update is called once per frame - void Update() + private void Bounce() { - + RB.velocity = new Vector2(RB.velocity.x, -(RB.velocity.y)); + RB.AddForce(RB.velocity * bounceForce, ForceMode2D.Impulse); } }