The goal I set out for this week was to iterate over and improve the dribbling mechanic I had created in the previous week. In addition to this, I also set out to complete basic version of a passing system by leveraging my ball physics component.
The dribbling system at the end of the previous week looked good, but it was very easy for the player to lose control over the ball as each dribble function call was called only when the either leg of the player was fully extended. This combined with me trying to predict where the player would be the very next frame did not pair well as the animation would trigger the dribble every 5-10 frame. This led to situation where I was trying to do deterministic calculations but the animation triggers themselves were non-deterministic as they were part of a blendspace.
In order to address this, I stopped calling the dribble function from animations and instead called it on every Tick to predict where the player would be the next frame and move the ball appropriately to that position by the next frame. This resulted in an exponentially better dribbling system as the ball always remained in control, completely independent of animations.
Dribble logic being executed every frame to get the ball to where it needs to be the next frame.
Adding an additive impulse force to push the ball instead of directly setting the linear velocity as this looks more natural.
A video showing the improved the dribbling system. (the ball even gets blocked by obstacles)
Although the dribbling system looks really accurate with varying ball mass and linear damping, there is a desync between the animation played and the movement of the ball which makes the movement look quite unnatural. In order to address this, I added in a new parameter to path prediction function to consider the number of frames over which the ball must be moved to a given destination, instead of just 1 frame. This made the ball physics component much more flexible as it can vary the forces returned based on varying frame rates supplied.
Modified GetSuggestedVelocity function which now considers the number of frames over which the ball is to move to the desired spot.
With the dribbling system functionally done, it was time to move onto the passing system. For this I reused the ball physics component to calculate the path from source to destination over a given frame period. Every time the user clicks the A/X button on the controller, if the controlled player has the ball under control, they pass the ball to the first other player in the level and the controller switches to control that player. The passing system was made easier for me as the ball physics system I had written was quite robust.
Two players passing the ball to each other.
The passing logic. The pass function on the player just pushes the ball to the target location using the ball physics component.
Overall, it was quite a productive week as I was able to get the dribbling system to a point where I am really happy with it functionally. I might consider revisiting it to work with animations in the coming weeks, tentative to other core mechanics being completed first.
The plan for the upcoming week is to make passing selections to pass the ball to different areas players, not just the only other one present in the level as that's not very dynamic. This is going to involve calculating controller stick orientation to pick a passing range, while also providing a lock-on mechanic if the chosen direction is close enough to another player.
Comments