After having worked in a completely deterministic game framework on Stardust Battle. A lot of my Unity projects started to embrace those ideas. This project in particular was well suited for determinism, as, to accurately predict the future, you have to be certain that all objects will react in exactly the same way every time you run the simulation.
Predicting the Future
The idea of predicting the future is really fascinating. In code the algorithm goes something like this:
Clone the model of the world.
Shoot a bullet in the direction of the player towards the mouse.
Tick the world 100 times.
Destroy the clone, and go back to the original world.
publicclassWorld{publicinttickNum=0;publicintturnNum=0;publicGameStategameState=GameState.EnemyTurn;publicPlayerplayer=newPlayer();publicList<Bandit>bandits=newList<Bandit>();publicList<Bullet>bullets=newList<Bullet>();publicintnextBanditSpawnTick=0;publicintbulletHitsScore=0;publicList<Position>gizmos=newList<Position>();publicPositionwind=newPosition(0.01f,0.01f);}// The original model.Worldmodel=newWorld();voidDrawPrediction(){Worldclone=LogicService.CloneWorldWithoutBullets(model);LogicService.ShootBullet(clone,input.GetShootDir());for(inti=0;i<16;i++)LogicService.Tick(clone);// Draw the what you see.}