Starting work on the wall clinger took a bit of time to get started, I am unfamiliar with a lot of the scripting formulas and tricks so I had to spend a good amount of time researching and experimenting scripting solutions to some very specific problems. Some examples:
- How to keep a consistent forward rotation when reorienting to different up direction based on surface normals.
- Later on how to set the forward direction to a custom value.
- The math needed to figure the appropriate length for a diagonal ray if I want it’s end to stop at ground level(trigonometry, oh how I wish I paid attention when I was younger).
The concept for how the script should work on the other hand was relatively simple. Above are some of my diagrams of me planning out the system, and below a gif showing how it works.
When given a movement direction, the wall clinger first sends out a ray to:
1- To check immediately ahead of it for aviated surfaces.
2- If this returns null it then checks down from the above rays end to check for ground at it’s current level.
3- If that is not found it sends a final ray, from ground level, that aims at a point below the avatar, to check for ledges.
When a true result is gotten the wall clinger then lerps from it’s current position and orientation, to that of the rays returned position and normal.
Additional Feature – Physics Layers
While developing this I also experimented a bit with physic layers. The wall clinger was set to only check for surfaces on the ShadowWall layer, and was itself set to the Shadow Layer. For the sake of experimentation I made a new layer, ShadowInteractables , that were set to physically interact with the isolated Shadow layer, and the rest of the normal physics.
Most likely I will be using script interactions and addForce events for this kind of effect in the final game, but I was good to at least research this approach.