I have a working elevator in my mountain now! Seems like a simple thing, but to get here I had to tear up a lot of code and reconsider so many parts, all the way back to player movement...
The elevator works, I just haven't filled in all the geometry, so enjoy a quick view of my mountain world from the inside out... : )
New Anim, State Switching and Queuing
First, to get the doors to close, elevator to zip to the requested floor, and those doors to open when you get there... all in the correct order, at the correct timing... and not to mention turn on/off the necessary colliders so you can't just step out into the void while travelling or fall through the shaft... not to mention disable the buttons in between so you can't interrupt en route... this all required a more full-featured DynObj and a real Queuing system for all the jobs, not just animation jobs. Now I can tell any DynObj (my class for any object in the game whose state needs to change) to run any animation, or wait half a second and then turn off a collider, or disable itself for 5 seconds then reenable itself. (Or I can tell it to SwitchState() which would be a collection of these jobs defined locally). The jobs queue themselves up and run at the allotted time nicely. My only worry now is how big DynObj is becoming... 300 lines to handle all the animation switching, queuing, receiving of triggers, and loading of states. And an Update call to chew through the job queue constantly. On every little button. It used to be three scripts, but I found it easier to combine them.
New Player Movement
Putting the character controller inside a mesh collider and trusting the physics to carry it up without a glitch was just not working. To get the player to travel along with an animating elevator car, I needed to parent the player to the car. But as soon as I did that, I got the jitters. Animation of objects apparently takes place on Update, whereas all my player movement takes place on FixedUpdate. The mis-match of timings produces jitter.
Fortunately, it was fairly easy to move all character motion over to Update, and I don't see any problems with that so far. Another problem was that my mouse-looking was in global space, which meant even though my player was parented, she would not rotate with the slightly rotating elevator car.
Easy enough to switch to localEulerAngles, but then... what's this? A visible jump in orientation as soon as the player enters or exits the car (parents or unparents, switching from global to local space...). I added a quick reorientation on trigger enter/exit and it worked okay. But there still seemed to be a little hitch sometimes as soon as the player would step in. For the longest time, I thought this was more Fixed Update business. Maybe the trigger gets evaluated with the physics, and my re-orientation is either too late or too early sometimes? Maybe the floors of the room and the car didn't match well enough and as we cross the threshold, the player hops? Do I really know my inherited PlayerMovement code well enough (I ended up re-doing the downward-shooting ground check ray, the one that is supposed to keep you glued to the ground when going down a slope)? I tore up a lot of code looking for this hitch. But no, it turned out it was just sloppy colliders. In the transition from the moving car to the static floor enclosure, the mesh wasn't quite closed, and I was hitting the edges on the way in.
I got paranoid of all the jitters after all the other problems the elevator highlighted, so I decided I wanted the player's head (camera) to ease a little bit in Y. The character controller by default is very touchy for uneven terrain. Stepping over every little rock would cause a jarring up and down motion. I can't really change that, so what if I ease the camera (which lives under the CC)? I stored the previous update's cam.position.y and then Lerped between where it was and where it should be. This worked, but again caused a bunch of local/global space-switching problems and jitter while riding the elevator. Even once I solved the jitter, the head would lag behind on the very fast-moving elevator and then catch up when the car stopped. Because of course, that's what I programmed it to do. I won't bore you with the details, but I finally figured out the right combination of parent positions and local adjustments to make to my stored values, and it works well now.
Leave a comment
Log in with itch.io to leave a comment.