GML Explain Surface normal and how to use it

I want to code a top down mini golf game and so far I understand that I need to find the angle of the wall so that I can find out what angle to move the ball at. So far I think it involves the surface normal but I don't know how to use a surface normal nor do I know what a surface normal is.
 

kburkhart84

Firehammer Games
The surface normal is quite literally what direction is perpendicular to the surface at that given point. So if you have a desk your monitor sits on...assuming it is flat and sitting normally...the surface on top has a surface normal pointing straight up. If you have a can of soda(a cylinder), the surface normal all around the can will be pointing away from the center outwards. This is commonly used in shaders for lighting calculations..and in your case you are wanting to use it to figure out which way to make a ball bounce. If you have a wall on the right of you and are standing on the left, the wall surface normal is pointing left(away from the wall). The floor you are standing has a surface normal pointing up, and the ceiling has a normal pointing down.

The solution is going to depend on how complicated your walls are and what they are made up of. The surface normal in a general sense is simply going to be the direction that points away from the wall. So if your walls are straight, then you can possibly just precalculate simply because you know what it is based on the graphic. Then you can calculate the bounce according to that. If your walls are curvy or more complicated, you are going to need to either break them down into primitives, or find an algorithm that calculates normals based on the surrounding pixels(I've heard of it but never found it or used it).
 

NightFrost

Member
A normal is a vector that is perpendicular in regards to its surface. Anything that reflects off the surface "flips" its movement vector across the normal. You're apparently working in 2D so you need only concern with x and y. Let's say the normal is at 45 degrees, and an object hits the surface with its movement coming in at an angle of 20 degrees in relation to the normal. This means it bounces off also at 20 degrees, flipped across the normal.
 
The surface normal is quite literally what direction is perpendicular to the surface at that given point. So if you have a desk your monitor sits on...assuming it is flat and sitting normally...the surface on top has a surface normal pointing straight up. If you have a can of soda(a cylinder), the surface normal all around the can will be pointing away from the center outwards. This is commonly used in shaders for lighting calculations..and in your case you are wanting to use it to figure out which way to make a ball bounce. If you have a wall on the right of you and are standing on the left, the wall surface normal is pointing left(away from the wall). The floor you are standing has a surface normal pointing up, and the ceiling has a normal pointing down.

The solution is going to depend on how complicated your walls are and what they are made up of. The surface normal in a general sense is simply going to be the direction that points away from the wall. So if your walls are straight, then you can possibly just precalculate simply because you know what it is based on the graphic. Then you can calculate the bounce according to that. If your walls are curvy or more complicated, you are going to need to either break them down into primitives, or find an algorithm that calculates normals based on the surrounding pixels(I've heard of it but never found it or used it).
Thank you for your help!
 
A normal is a vector that is perpendicular in regards to its surface. Anything that reflects off the surface "flips" its movement vector across the normal. You're apparently working in 2D so you need only concern with x and y. Let's say the normal is at 45 degrees, and an object hits the surface with its movement coming in at an angle of 20 degrees in relation to the normal. This means it bounces off also at 20 degrees, flipped across the normal.
could you explain how to calculate this for a more complicated shape

This is exactly what I want but I don't know how to use it.
 
Top