0
votes

I am making a 2d top-down bullet-hell game and want some help in getting a bullet to bounce off a wall. the variable movement is the bullets vector2 and the tag boundary is the tag given to the walls. I know from different tests that the trigger works like it should (so it activates when it hits the wall) but the movement just does not reflect, it keeps on moving in the same direction.

EDIT: I changed vector3.reflect to vector2 and it still does not work.

private ContactPoint2D[] contacts = new ContactPoint2D[2];

void OnTriggerEnter2D(Collider2D other)
{
    if (other.tag == "boundary")
    {
        other.GetContacts(contacts);

        Vector2 normal = contacts[0].normal;

        movement = Vector2.Reflect(movement, normal);
    }
}
1

1 Answers

0
votes

it might be simple but have had a look at using Vector2.Reflect as you are using 2D for everything else.

And I came across this post it might help. Unity - how to use Vector2.Reflect()