Moving Rigidbody with mouse and proper sync
Hey hey
I'm working on a football game: (The video is laggy, the game is not. What is shown in the video is when I use WASD controls to move the germanball and hit the football. It is proper synced with the footballs velocity on each screen..
Now I've been trying for a long time to make something like this by using mouse input. I raycast in normal Update() to get the position of where the player should be. Then I use tsRigidbody2D.mosePosition to move the germanBall...
However, this doesn't keep any velocity and only pushes the ball.
By pushing it, it also becomes out of sync.
I have tried calculating the velocity from the mouse and adding the direction plus some extra speed when you hit the ball. It sort of works, but again, it desyncs when you accidently move the ball by getting too close to it. Also I'm not sure if I should save the TSvector pushdirection in the input and then set it in the SyncedUpdate....
This has been a headace. I've done many, many singleplayer and local games in Unity and this is my first real attempt at making a network game. I can't get my mind around it.
Video example of using rigidbody.moveposition (without the extra force added).
If I just somehow could match the same thing I do with the WASD keys, then it would work!
I'm working on a football game: (The video is laggy, the game is not. What is shown in the video is when I use WASD controls to move the germanball and hit the football. It is proper synced with the footballs velocity on each screen..
Now I've been trying for a long time to make something like this by using mouse input. I raycast in normal Update() to get the position of where the player should be. Then I use tsRigidbody2D.mosePosition to move the germanBall...
However, this doesn't keep any velocity and only pushes the ball.
By pushing it, it also becomes out of sync.
I have tried calculating the velocity from the mouse and adding the direction plus some extra speed when you hit the ball. It sort of works, but again, it desyncs when you accidently move the ball by getting too close to it. Also I'm not sure if I should save the TSvector pushdirection in the input and then set it in the SyncedUpdate....
This has been a headace. I've done many, many singleplayer and local games in Unity and this is my first real attempt at making a network game. I can't get my mind around it.
Video example of using rigidbody.moveposition (without the extra force added).
If I just somehow could match the same thing I do with the WASD keys, then it would work!

0
Comments
-
Hi @Code, are you directly updating the rigibody when you move the mouse (in the Unity's Update)?0
-
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.
0 -
@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?0 -
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 TS0 -
Just get/send the input, and do the calculations which result from the input on the sync update.0
-
@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?0