Custom Physics


I am trying to implement my physics solution. I need something 2D and very simple & fast (specially considering Fixed Point math). I have basic collision working, but I am not sure how to implement it with TrueSync.

For example - I was hoping to have my Physics Engine main loop be run on OnSyncedUpdate() on a True Sync gameObject.
All of my physics objects inherit from TrueSyncBehaviour.

This is my pseudo code, inside the main loop:

- initialize all new shapes (remove old ones)
- Move shapes
- Handle triggers
- Finally, run CustomUpdate on each object (if any).

I have 2 questions so far:
1) Should this main loop work, or not? I am assuming it does - because even though I am accessing each object through custom method -- all objects are accessed through 1 OnSyncedUpdate on main loop.

2) I notice some methods can't be run this way (through main loop) due to player ownership.
Since a player is also a shape (that collides other shapes), I need it to use the same physics main loop.
Do you have a recommendation how to work around this?
Right now I am getting Warning: 'You can't access an input in a TrueSyncBehaviour that has no player owner.'
I could move the player code, to OnSyncedUpdate(). But then I don't know how to fit it into my main physics loop.
Or to put it into another way:
How would I call a method on the object containing "TrueSyncInput.GetInt(INPUT_KEY);" but not through "OnSyncedUpdate" but through some other method instead (indirectly calling OnSyncedUpdate).

I hope these make sense.



  • Hi @Kreso, nice (and tough) decision, you can take a lot of advantages in having a faster physics. Answering your questions:
    1 - I think it should work too, if you have a code that runs the same way in both machines and in the same order it should be ok as you are not breaking determinism.

    2 - Well, you can have a central TSBehaviour to manage physics and if you need get players inputs you can use "TrueSyncInput.GetAllInputs" or "TrueSyncInput.GetPlayerInput".

    Any additional questions feel free to ask us.