- Home /
Multiplayer Click-to-move
Hello.
I'm currently working on multiplayer game with click-to-move character controller. I thought it is good idea to send RPC every time player clicks LMB to move, instead of observing transform using NetworkView to reduce bandwith consumption. Unfortunately I'm facing two problems:
1. Position on spawn
I'm using following code to spawn the player
GameObject player = (GameObject)Network.Instantiate(playerPrefab, transform.position, Quaternion.identity, 0);
Problem is that when I move character and then connect to the server as a new client, it spawn already connected player at (0,0,0) from newly connected player perspective (transform.position of the GameObject with the script attached), because I dont know how to get player position before instantiating it. Any ideas?
2. Problem with physics
When one player hits another while moving, he will push it (because both have colliders attached). But after that, even when they are away from each other, some weird physics are affecting both of them (and after object will move futher than "Stopping Distance" in NavMeshAgent, it will try to move back to the set destination which causes object to shake around). This happens only on clients.
PS. Is it even good idea to use RPC when player presses LMB instead of observing object's transform? Is there something I didn't think of, which can cause big problems later?
For the first question: You see them in (0,0,0) because the new player doesn't know that they moved. So two workaround:
you should change your RPC mode to RPC$$anonymous$$ode.AllBuffered. The buffered is the key, so the new players will also see the changes.
or just change the whole to obsevation
I can't help in second.
Your answer

Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Physics.Raycasy not really using Layermask? 1 Answer