I want to know how the AI calculates where the ball lands
It is nice to see the project you share! I am a Unity learner and trying to repeat your work in Unity. But the code of AI is a little hard. I have read the physics.js but I am a Javascript noob and not totally understand it. 😢
Could you use a simple text or some mathematical formulas to describe it? I will appreciate that!
(I am not a native English speaker, maybe you can understand my statement xD)
@DavinciEvans Sorry for my late response.
The landing point of the ball is calculated by the function calculateExpectedLandingPointXFor:
https://github.com/gorisanson/pikachu-volleyball/blob/82037354d00b3a35fdb16ad27ab0733eb8010be7/src/resources/js/physics.js#L733-L788
As you can see, the code in while (true) { ... } block (at line 746-786 of the code above) in the function calculateExpectedLandingPointXFor is similar to some part of the code in the function processCollisionBetweenBallAndWorldAndSetBallPosition, which is the following:
https://github.com/gorisanson/pikachu-volleyball/blob/82037354d00b3a35fdb16ad27ab0733eb8010be7/src/resources/js/physics.js#L423-L485
What does it mean? I guess maybe you can see it now:)
Right! The calculateExpectedLandingPointXFor function first makes a copy of the ball and it just loops through the processing of collisions between the copied ball and the world, and if it detects the copied ball is touching ground, it read the x coordinate of the copied ball. This x coordinate is the point where the ball lands on the ground!
There is also a function expectedLandingPointXWhenPowerHit which is used for calculate the landing point the ball when the ball is power hit:
https://github.com/gorisanson/pikachu-volleyball/blob/82037354d00b3a35fdb16ad27ab0733eb8010be7/src/resources/js/physics.js#L955-L1032
I think you can now analyze this function by yourself!
If you have any more question or need some help, please let me know:)
Sorry for my neglect and the very very very very late response. ;)
I just noticed this open issue and saw your reply. Although I have already solved this problem using reinforcement learning and behavioural trees, thank you very much for your serious reply, which still inspires me and gives me a lot of inspiration. And it is indeed a good approach, I need to do a lot of practice to beat this AI.
I have a few more questions: although I can predict the landing point, how can I tell when to jump and when to use the power hit?