Vector2.Reflect not working

I was making a ball bouncing off a wall but it did not work.
Can someone help me?

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class BounceOFF : MonoBehaviour
{
    private bool isPressed;
    private Rigidbody2D objectRigidbody;
    private Vector2 newThing;
    // Start is called before the first frame update
    private void Awake()
    {
        objectRigidbody = GetComponent<Rigidbody2D>();
    }

    // Update is called once per frame
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.E))
        {
            isPressed = true;
        }
    }

    private void FixedUpdate()
    {
        Vector2 addForcing = new Vector2(8, 0);

        // if player press E then add force
        if (isPressed)
        {
            objectRigidbody.AddForce(addForcing, ForceMode2D.Impulse);
            isPressed = false;
        }
    }

    private void OnCollisionEnter2D(Collision2D collision)
    {
        // Why this code doesnt work?
        if (collision.collider.name == "Square")
        {
            Vector2 inNormal = collision.contacts[0].normal;
            newThing = Vector2.Reflect(objectRigidbody.velocity, inNormal);
            objectRigidbody.velocity = newThing;
        }
    }
}

Hey there, im not at a desk to rewrite this for you, but this should be the correct structure you need, please try this instead in your code:

void OnCollisionEnter(Collision2D collision)
{ 
    if (collision.collider.name == "Square")
    {
       Vector2D inVelocityDirection = objectRigidbody.velocity;
       Vector2D inNormal = collision.contacts[0].normal;
       Vector2D newVelocityDir = Vector2D.Reflect(inVelocityDirection , inNormal);
       Debug.Log($"Old direction = {inVelocityDirection} to new direction {newVelocityDir}");
       objectRigidbody.velocity = newVelocityDir;
    }
}

With any luck, you can simply replace the collision method, without any, you may have to adjust some bits. Apologies for not being able to write the code into your existing script, but its a bit tough on the mobile to do this practicably :slight_smile:
Happy to go through it with you later or help live this afternoon, but wont be home [back at a bigger screen] til then
:slight_smile: Cheers and good luck