Untitled
unknown
plain_text
2 months ago
645 B
2
Indexable
using System.Collections; using System.Collections.Generic; using UnityEngine; public class BallController : MonoBehaviour { public float bounceForce = 10f; private Rigidbody2D rb; void Start() { rb = GetComponent<Rigidbody2D>(); } void OnCollisionEnter2D(Collision2D col) { // Apply bounce force to the ball on collision if (col.gameObject.CompareTag("Player")) { Vector2 bounceDirection = (transform.position - col.transform.position).normalized; rb.AddForce(bounceDirection * bounceForce, ForceMode2D.Impulse); } } }
Editor is loading...
Leave a Comment