In this Unity3D project, I got to demonstrate vector projections and basic colliders. Spheres in the world are projected onto multiple objects in the scene. The spheres also are capable of colliding with a barrier and a cylinder. The math for determining the projection and collisions are self-calculated (i.e. no math libraries or rigid bodies components used).
For observation, users are able to modify the sphere travel path, barrier position and orientation, and the cylinder endpoints.
Projections
To help demonstrate of vector projections, spheres in the scene are spawned at a constant interval. The sphere is then projected onto a barrier and a cylinder. For the projection on the barrier, the projection is represented as a flat black sphere.
This simple concept is an easy way to help manually generate shadows of your objects in the scene. For the projection on the cylinder, white spheres were added to the scene to represent the projection if the sphere was less than a certain amount of distance away from the cylinder.
Collisions
As mentioned earlier, the spheres in the scene can collide with the barrier and the cylinder in the scene. Collisions are detected based on the size of the sphere and location of the barrier or cylinder. When a sphere collides, the sphere's direction is reflected off the collided object (based on the colliding object normal vector). In the case of the barrier, the normal vector is simply the perpendicular vector from the flat surface:
In the case of the cylinder, the normal is the vector from the sphere's projected position onto the cylinder to the sphere itself.
To see a short demo, you can check out the video here:
Languages and Tools Used:
Unity3D, C#
Comentarios