Week 5
Since, there is a ground now, the hero should walk on it instead of somewhere in the sky. I want gravity and make use of the colliders I added in week 3 some colliders. Let's look at the colliders first.
hero2 is the model imported from Blender. Attached to it are the IK nodes mentioned in week 3.
Attached to PhysicsContainer are CharacterBody3Ds and CollisionShape3Ds for the feet and body. I use them for the hero's controls and physics. PhysicsContainer node type is Node, which negates any parent transforms. So, why split up the hero into three CharacterBody3Ds? I want to have full control over the feet. The body is added for getting collisions with coins, enemies, etc.
The split means having to deal with it in code. There is no default character controller for my unique locotion method. Let's look at code.
I let the non-active foot fall down and then apply its traveled distance to the active foot. Using move_and_slide for both makes the collisions work like expected. However, it can also shorten the distance between the feet. This is how I correct this.
I move the active foot along the vector of the other foot to the ative foot scaled by the desired feet distance. Using move_and_slide here means that the feet distance is corrected once there is enough space to do so, possibly at a later point of time.
So, what is the desired feet distance? Well, the bigger, the faster the player can walk, but the more goofy the hero looks. I use the initial feet distance as the desired distance, so I can change it in the editor with a visual preview. Then I played the game to choose an appropriate value empirically.
The body is moved in the middle between the two feet and has no collisions with the parkour.
For letting the hero look in the correct direction, I copy the input basis to the hero's body's transform basis.
Putting it all together, this is what it looks like.
One last thing I do this week, is adding a fullscreen toggle to the game. While this does not change anything for the player, it makes recording gameplay footage and watching people play the game a little bit easier.