Moving Rigidbody with mouse and proper sync

Options

Comments

  • Code
    Options
    Apparently I must have have forgotten how I make links... xD

    Here is the first video: VIDEO 1

    And the second: VIDEO 2
  • JeffersonHenrique
    Options
    Hi @Code, are you directly updating the rigibody when you move the mouse (in the Unity's Update)?
  • Code
    Options
    Hi @JeffersonHenrique

    First I raycast and figure out where the mouse hits


    Then afterwards, I clamp the values (because I only want the players to be able to stay inside their respective gaming area).

    And then I save the vector value.



    And then at last, I update the position by using the tsRigidbody2D.MovePosition.


    But it causes desyncs...
    Works 100% with WASD keys, but thats because the player is moved by velocity rather than MovePosition.
  • Code
    Options
    @JeffersonHenrique is there a way I can mimic the velocity from WASD keys?
    I have been thinking about moving the player (through velocity) towards the point I click with the mouse. Then do some checks to ensure it doesnt overshoot. Not a very elegant solution, but it might enable the rigidbodies to properly sync the velocity?

    Is there another way I can ensure that the ball is in the same position? Can I send its position to both players at the same time or will that break the point of using truesync?
  • espii
    espii
    edited January 2018
    Options
    Physics2D raycast???? U should be using TSPhysics2D with TSCollider2D, TSRigidbody2D.

    Unity's physics is not deterministic so u gotta use the much slower version from TS
  • Code
    Options
    @espii
    Does it make a difference since I convert it to a TSvector2 in Update() before going to SyncedUpdate()?

    It doesn't visually, they both move to their positions perfectly. But do you think that this is the reason TSrigidbody.moveposition doesn't move them as intended?
  • espii
    espii
    edited January 2018
    Options
    Just get/send the input, and do the calculations which result from the input on the sync update.
  • Code
    Options
    @espii So I should do the TSPhysics2D in Update and then send it over? :)

    More stuff about the rigidbody.MovePosition -> I've done this in a game before, where it was a singleplayer game so when I moved the player with the mouse and hit other objects, the objects just moved a bit (because of collision). But these collisions are not sent automatically when you move the player in Truesync and hit the ball and that's where I think it gets out of sync. Can I do something to prevent this?