SCRIPTING ARTIFICIAL GRAVITY AND SMOOTHING THE ANIMATIONS

Words
466
Reading
3 min
Listen
Play
5y

boy_scene_banner.jpg

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.

st1.gif

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.

st_5.jpg

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.

st_2.jpg

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.

lane_movements.gif

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.

st2.gif

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.

st_6b.jpg

I had a bit of issue with the jump animation, It kept leaving the root character position and zooming back in like a boomerang.

st_7.gif

I figured that the problem was from the mixamo fbx import, I solved it by tweaking the animation keyframes within Unity.

st_4.jpg

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.

st_8.gif

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

hive_banner_2.gif

SCRIPTING ARTIFICIAL GRAVITY AND SMOOTHING THE ANIMATIONS | Ecency