I want to make the ball reverse direction when collided with a wall and move to that direction when clicked, but unfortunately that’s not what I have in my game. Here is the comparison between my game and dunk hit: My Game, Dunk Hit
Here is the code:
void Keybinds() // Keybinds and mouse binds
{
if (Input.GetMouseButtonDown(0)) // Left mouse button
{
Debug.Log(“Mouse Pressed”);
if (Touched)
{
Circle.velocity = new Vector2(2f, 3f);
Touched = false;
}
else
{
Circle.velocity = new Vector2(-2f, 3f);
}
}
Collisions:
protected void OnCollisionEnter2D(Collision2D collision)
{
var Speed = LatestVelocity.magnitude;
var Direction = Vector3.Reflect(LatestVelocity.normalized, collision.GetContact(0).normal);
Circle.velocity = Direction * Mathf.Max(Speed, 0f);
Touched = true;
Debug.Log(“Ball has hit something”);
}
}