top of page
  • Writer's pictureBreck Massey

Physics Playground


When ever I make a game in Unity I always want to use the complex colliders. The simple colliders such as squares or circles work but sometimes I want more. The poly collider can be used for this but, on my computer, they would always heavily impact performance. I wanted to try to make my own physics simulator with complex collisions. I decided to do this using this unique property. The property is if you draw a ray from a point you can tell if it inside or outside of an object based on the number of lines it passes through. If it passes through an odd number of lines it is in the object. If it passes through an even number of lines it is outside the object. For example, If there is a point inside of a square then the ray would go off to the right. The ray would pass through one wall. If the point was outside of a square then the ray would go off to the right. The ray would pass through two walls. This can be seen in the image below.

This concept works on any shape no matter how complex or if it is convex or concave. This is very useful. Once the point is inside of the shape, the next step is to move it back out. This is done by looping through all of the lines of the shape and finding the closest point on the shape. Then move the inside point towards the closest point on the shape.


In the end I get pretty accurate collisions. This works in concept but in actuality my version has a few inaccuracies, but it is still fun to play with.



Play With It Here:



5 views0 comments

Recent Posts

See All

Comentarios


bottom of page