top of page

Procedural Tree Generation (for VR class project)

Screen Shot 2023-02-08 at 1.57.51 AM.png

This code comes from a system that generates trees. This simplified section is the part responsible for generating the base, or trunk, of the tree (I use the term tree here, but it can abstracted out to mean any line-like structure, like a stalactite on a cave ceiling, branches, and so on).

A for loop iterates over the amount of objects to spawn, pointing a ray straight down and creating an object at the hit point. That object is then slightly randomized with respect to its scale and rotation. At the next iteration, another object is spawned, but this time the ray hits the top of the last spawned object, which is then made slightly smaller than the previous piece, and placed on top of it. By the end of this loop, there are a number of objects instantiated on top of the other in a line-like structure.

Movement Along Slopes (Ongoing Project)

Screen Shot 2023-02-08 at 1.44.33 AM.png

This code illustrates a method for calculating the movement direction of a player in 2D along sloped surfaces. While it's somewhat confusing to wrap your head around a cross product within a cross product, the player's inputted movement direction is transformed to a new direction aligned with the surface normal of the slope.

Body and Head Rotation (Project: Island)

Screen Shot 2023-02-08 at 1.21.01 AM.png
Screen Shot 2023-02-08 at 1.24.12 AM.png

The above code demonstrates how the rotation was calculated for the robot enemies in my 3D game Project: Island. In the game, these enemies can navigate around spherical planetary bodies, so their bodies need to be aligned with the planet normals, while their heads need to be able to look at the player at the same time. 

The top code block (the Update method) shows how the head rotates to look at the player only on the y-axis, while the bottom (the method Rotate) demonstrates how the full body of the robot rotated to match the ground surface's normal and direction of movement.

For a more comprehensive code sample, look at the Tiny Search Engine project created in Dartmouth's Software Design and Implementation course.

bottom of page