Reflection Script Doesn't always work properly

Hello! I am attempting to create a reflection script that causes a GUI(textlabel) to bounce off the edges of walls using math.clamp .

The gui glides perfectly when i set the direction, but problems occur when I want it to bounce. Sometimes it bounces in the direction expected, but sometimes it doesn’t at all, even gets stuck in corners at times because of this.

Code:

function CalculateBounce(currentNormal, normal)
	local reflect = currentNormal - 2*(currentNormal*normal) * normal
	return reflect
end

I have the equation for this but I may have done something wrong. This is the video of it:

Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.

sorry, OBS didn’t record the video properly and i did not notice. Hold on ill re do it :frowning:

EDIT: i think my drivers are bad, it won’t capture studio. Maybe its openGL?

The textlabel is probably getting stuck because it is past the wall when it bounces.

When I made something similar, I multiplied the x and y velocities of the textlabel by -1 and then set the position to be on the edge of the wall in case it went past the wall.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.