0
\$\begingroup\$

I am trying to do a simple reflection of a point entity off of an arbitrary surface that contains it. It doesn't have to be physically correct but essentially the goal is to do the following:

if (isOutsideOfContainer()) {
   placeOnNearestEdgeOfContainer()
}
float2 container = getContainerNormal();
float2 newVelocity = f(velocity, container);

So essentially I am placing the out of bounds point on an edge of the container, getting the normal of the edge at that point on the container, and using that to calculate the new velocity vector.

How exactly do I do this?

I am doing this so that particles can "bounce" off of the edge of the screen as computationally cheaply as possible. Sometimes the screen will be a boring rectangle but other times it might be an iPhone X, or have half of its corners rounded. No-matter what the screen I want to properly simulate its bounce.

\$\endgroup\$

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.