Seeking Advice regarding controller setup for game where player can fly and attach/detach from terrain
I'm new to Unity and C# and having a lot of fun using it, but got in a bit over my head regarding this controller/mechanic. Video here.
Some details:
The main controller is a single script that controls flying and traversing the terrain, but I made the attaching and alignment separate for now so they are easy to switch in the inspector.
The two attach methods I've been exploring are a single ray with collision capsule (set to trigger), and the Second is a dual ray cast to average the surface normal. Neither seem work very well when confronted with small radius corners. I may not be averaging the dual raycast correctly but thought there may also be an issue with collision.
I'm currently using the barycentric example since it deals with faces, just plugging into my script. and using
transform.rotation = Quaternion.Lerp(transform.rotation, surfNormal, Time.deltaTime * interpToNormal);
The game is locked to two axis (x, y) and the ship rotates on the z
Some questions:
Should I separate the flying, attaching, and terrain traversal into different component scripts?
The terrain is mesh collision, but the rotating chunk is set to convex since its a rigidbody. It doesn't seem to have normal information - is the only way around this to use a bunch of capsules to fit the shape?
I've found a few leads for things like cars and walking on round objects, but any suggestions for attaching to mesh in this way?