Moving Better
FPS movement was working okay in the previous Foxhunt, but I wanted to fix two major flaws: sliding up the steepest of hills, and bumping down a smooth incline.
Before, the motion was physics-based, with a capsule collider and velocities added to a rigidBody. This was mostly fine, enabling the player to slide smoothly over any surface, be blocked by other colliders, and have physical gravity keep them on the ground.
One problem was though, with enough oomph, the player could really slide over ANY surface. Even 80 degree grades. You could FORCE yourself up on top of the top-heavy box, for example, without pushing it over first and using the boards. Most of my surfaces were dilapidated and slanted, so if I hadn't gone through the extra work of putting hard 90 degree box colliders up, the player could have force-climbed almost any structure.
The other problem was, when the player walked DOWN an incline, they would bump unpleasantly every half second or so. The physics trajectories were only applied in 2D, a flat plane, so when they moved forward, but there was no ground immediately underneath (in the case of going down a hill), they would zip forward as if the ground was flat, while the physical gravity caught up and pulled them down to the hill's actual surface a few frames later. It was like suddenly remembering gravity and falling a few inches every half second.
To solve these, I switched to a character controller instead of a physical collider and found this nifty script with a few extra bells and whistles.
Character controller: I don't quite know how a character controller works under the hood... it's a Unity thing that seems like a non-physical capsule collider?... but a lot of things come for free. Like, for example, the ability to set a slope limit: the maximum grade your character can slide up. As well as a step offset: the maximum height your character can step up without being blocked.
FPS Walker Enhanced script: this script pairs well with the character controller and adds some other niceties. Including the one I was looking for: an anti-bump measure. As far as I can tell, all this script is doing is adding a certain amount of downward motion each physics frame. If you happen to be going down a hill, well that's fine: you're moving down to meet the hill. If you are not going down a hill, well that's okay too because the character controller collider will compensate and keep you from going through the ground.
Here is how the script's anti-bump factor ended up integrating into my input and motion code under FixedUpdate:
vel = Vector3.Normalize(new Vector3(moveInputRaw.x, 0, moveInputRaw.y)) * mag + (Vector3.down * m_AntiBumpFactor); vel = transform.TransformDirection(vel) * moveSpeed * moveSpeedMult; c_controller.Move(vel * Time.deltaTime);
Most of the rest of the script is about jumping (which I don't need) and sliding (which I hadn't thought of, but maybe I'll find a use for...). The script didn't include code for mouse-looking, so I'll talk about some improvements there in the next d'log...
Foxhunt
the full game is coming!
Status | In development |
Author | anomalina |
Genre | Puzzle |
Tags | 3D, Atmospheric, Escape Game, First-Person, Relaxing, Unity, Walking simulator |
More posts
- Walkabout Foxhunts!Jul 18, 2021
- Hunting for Perfect SSAOSep 27, 2020
- Performance ExperimentsSep 13, 2020
- Philosophy and the Weight of Things (Dragging)Aug 19, 2020
- Ladders!Jun 15, 2020
- Elevator!Apr 03, 2020
- First New PuzzlesMar 25, 2020
- Q&A at a Local Art GalleryJan 09, 2020
- Mountain WIP 01Nov 27, 2019
- Proximity-based "Holes"Nov 21, 2019
Comments
Log in with itch.io to leave a comment.
If you don't mind my asking, how did you implement the enhanced script? I attempted it with a test project, but nothing seemed to happen.
Well, I can't really tell what's going on in your project, but I know you need a character controller component on whatever the script is on (whatever you're trying to move). Check on that, check on your inputs, make a "Run" button in inputs. Also, if you mean the thing just isn't mouse-looking, that is true... enhanced walker script doesn't deal with mouse input.
Yeah. I'm assuming it's a countermeasure to keep people from dragging and dropping code without tweaking it first.
Wait... The Original Was Just A Demo!?!?! Wow!! Dude Great Work!! Keep It Up!! Love The Style, Love The Animations, Love The Puzzles!! Can't Wait To See What Else You Have In Store!! I've Played The Original On My Channel If You'd Like To Check It Out:
KEEP UP THE GOOD WORK!!
Love that you're making dev logs during development! Have you already or are you planning on covering how you created those awesome fox animations or the cards UI? Those two bits really stood out to me when I played it!
Oh! Okay... ha ha... I didn't really think of the animation itself being interesting to anyone, since that is what I know how to do. The rest of it is me learning, and keeping this diary of what I learn...
But yeah, absolutely... I'll do that when I get there! THanks Adam.