Okay, I know it’s been a couple weeks, but I found I had to tie up some other pieces of code first.
I’m starting to implement this, and as I look at it, there are a couple changes I think I ought to make.
As I look at the code I need in the actual classes I am building, I think I want to create a new set of functions to be called.
I would call a list of function in all the objects on the list, in an order like this:
void preMove()
void Move()
void postMove()
void Check()
void postCheck()
And strictly speaking, I would never run FixedUpdate in any of the body classes. In all the child classes, I would simply override the preMove, postMove, and PostCheck functions to handle all the stuff that the individual class needs.
Now as such, I would just need one class to call those functions from within FixedUpdate. (I would probably use my GameManager, since it is a single persistent class.) So this one class would have this:
void FixedUpdate() {
Body.PreMove();
Body.Move();
Body.PostMove();
Body.Check();
Body.PostCheck();
}
This would also bring an unintended benefit that I don’t need to bother with script execution order. One single script calls the functions in order on one FixedUpdate.
Does that look like it would work right?
The only thing that still remains that I think I would need to handle is making sure that the player is updated first, and the camera is updated second. This is because (as far as I can forsee) all other objects will have their code dependent on the camera’s position, because their behavior will change if they are visible or not. (I mean, I guess being off by one frame won’t be a big issue, but still, I ought to set them up properly.) My first thought is that I could simply add a couple calls in that list that just directly call the player, and then the camera. But then the player would get called to move again when Body.Move() is called. I guess I could override the player’s move() function so it does nothing and the special PlayerMove() function does all of that, but that feels a bit convoluted.
Also, I wonder if there is a problem with calling functions like Body.Move() when there are no bodies in the scene. I’m thinking of situations like being on the main menu before the game starts, there will not be any bodies in the scene. Will that cause problems if the GameManager is trying to call static functions from the body class?