Public Group

# Mirror an angle?

This topic is 3855 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hey. Say I have an object coming in at say 45 degrees to a surface above it, it will bounce off at a mirrored angle. I guess my question is, what would the formula be to work this out? And would I need a different one for a vertical surface? A different one for a different direction? I'm making a simple breakout game and obviously would like to make the ball bounce.

##### Share on other sites
In the case of breakout the ball is interacting with only vertical and horizontal surfaces. This is a good thing because we can employ a simple trick to calculate the reflected vector.

Lets say the ball's direction vector is <x,y>.

That vector reflected off of a horizontal surface is is <-x, y>
That vector reflected off of a vertical surface is is <x, -y>

##### Share on other sites
Are you just using horizontal and vertical surfaces? If so, just negate the horizontal velocity when hitting a vertical surface, and negate the vertical velocity when hitting a horizontal surface.

##### Share on other sites
At the moment I'm just using an angle and calculating the x and y real time, is there a way to just use the angle?

Also, what would be the formula for a slanted / diagonal surface?

##### Share on other sites
Quote:
 Original post by dwfaitAt the moment I'm just using an angle and calculating the x and y real time, is there a way to just use the angle?Also, what would be the formula for a slanted / diagonal surface?

It wont be possible until you familiarize yourself with the concept of a direction vector.

##### Share on other sites
Well I am familiar with vectors. Not sure why I picked to work with angles really. I've converted the code to have a double vectorX and a double vectorY, to be multiplied by a double moveSpeed variable. So all I would do is -vectorY for horizontal and -vectorX for vertical?

How would I go about diagonal / slanted surfaces? Would I need the angle of the surface?

##### Share on other sites
Quote:
 Original post by dwfaitWell I am familiar with vectors. Not sure why I picked to work with angles really. I've converted the code to have a double vectorX and a double vectorY, to be multiplied by a double moveSpeed variable.

I'm not sure what you're referring to as the "angle" here. Those sound like vectors to me.

Quote:
 Original post by dwfait So all I would do is -vectorY for horizontal and -vectorX for vertical?

Yes, for simple reflections off of horizontal and vertical planes.

Quote:
 Original post by dwfaitHow would I go about diagonal / slanted surfaces? Would I need the angle of the surface?

You would need the normal vector of the surface. This will work in 2 or 3 dimensions:

I_R = I - 2*(N dot I) cross N

I is your incident vector, I_R is your resulting reflected vector and N is the normal to the surface the incident vector is reflecting off of.

##### Share on other sites
Quote:
Original post by fpsgamer
Quote:
 Original post by dwfaitWell I am familiar with vectors. Not sure why I picked to work with angles really. I've converted the code to have a double vectorX and a double vectorY, to be multiplied by a double moveSpeed variable. So all I would do is -vectorY for horizontal and -vectorX for vertical?How would I go about diagonal / slanted surfaces? Would I need the angle of the surface?

You would need the normal vector of the surface. This will work in 2 or 3 dimensions:

I_R = I - 2*(N dot I) cross N

I is your incident vector, I_R is your resulting reflected vector and N is the normal to the surface the incident vector is reflecting off of.

Would I be right in thinking that the Normal is the vector of the line that is perpendicular to the surface?

##### Share on other sites
Quote:
 Original post by dwfaitWould I be right in thinking that the Normal is the vector of the line that is perpendicular to the surface?

Yup. IIRC is must also be unit length.

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 15
• 14
• 46
• 22
• 27
• ### Forum Statistics

• Total Topics
634049
• Total Posts
3015239
×