I'm finally approaching the challenging aspects of scripting the physics and animations of this character. The important aspect was first defining the gravity variable and plugging it into the Vector3 components.
It took me quite a while to figure out the right approach.
As you can see, the character turned superman for a bit hehe...
I tried to use the (controller.grounded) method as I did in my previous attempt at this project but for some reason, the physics system was unreliable during testing. After a bit of research, I discovered that I need to create an artificial gravity system, so I solved this floating issue by using the Ray constructor.
Basically, as the name implies, it's like a ray of laser pointing at the ground, testing if the character is grounded or not, with that metric I can easily adjust and test the gravity variable until I get it right.
The ray lines is very visible in debug mode, It leaves a trail which also helps me gauge the jump height from an objective angle.
SMOOTHING THE ANIMATIONS
Now that I solve the gravity issue, I had to to move on to the animation issue, I discussed about lane movement issue in the last episode.
As you can see above... the lane changing looks like it was gliding across, I figured a solution would be to implement a buffer animation when switching lanes, I needed something to interrupt his running stride.
Now with the buffer animation in between the lane changes, It looks a bit more dynamic and less laggy.
I also had to incorporate other animations into the character (jump, left, right) My animation window is starting to look crowded.
I had a bit of issue with the jump animation, It kept leaving the root character position and zooming back in like a boomerang.
I figured that the problem was from the mixamo fbx import, I solved it by tweaking the animation keyframes within Unity.
I just edited all the position z-axis properties of the animation, I override all the position.z values to zero in all the keyframes so that it doesn't leave the root position. Now the animation stays in place with the character.
WHAT NEXT
I can't wait to get to the more fun part of 3d asset building and the sky box, I've figured out a dope idea for the sky box that I can't wait to try out, also I need to build another street tile. I would need a total of 10 street tiles in total, then I would spawn them at random as the game character progresses.
That is all for now, Join me next time as I tackle this issues... thanks for your time :)
Check out my previous episode here:
SCRIPTING THE VECTOR MOTIONS AND LANE MOVEMENTS