I am working on sports game. I have simple scene with terrain, ball (with rigidbody) and one animated character. Currently I am testing ballistic trajectory and collisions. So I add velocity to ball (I know that AddForce is recommended, but I use this to predict ball location at any time), and I move character to desired location to collide with ball.
Problem is that each time I restart scene, collision is different. Sometimes there is no collision at all, sometimes ball bounces to one side, sometimes to other etc.
I don’t use any Math.Random function. I run the same code and get different results each time.
How is this possible, and which part do you think contains this randomness (is it physics update, Mecanim animator…)?
The randomness comes mainly from the variation of your framerate. Physics are calculated within the FixedUpdate loop. However it runs asynchronous to your (visual) Update. Animations are usually calculated from the normal Update loop.
Every “event” that comes from the visual Update loop will cause “randomness” since it’s always executed at a different time.