- Home /
Movement speed of 2 players not matching
I am making a multi player space adventure, i have created controls for player 1 using, standard WASD keys, and other player is controlled by the arrow keys. Both the players are supposed to have the same speed but the player 2, i.e the one controlled by arrows, is more responsive and fast than player 1, despite all the variables including speed are the same for both, so please help as i dont want to change the controls and i want them to move the same way.
Code goes like, Player 1 If(input.getkey(keycode.w)) { Transform.translate(vector3.up * time. deltatime*speed) ; } And so on....
Player 2 If(input.getkey(keycode.uparrow)) { Transform.translate(vector3.up * time. deltatime*speed) ; } And so on.....
Are both movement sections in the same update loop? You may want to make them both FixedDelta Time just to ensure they are happening at the same time. It's hard to say, but theoretically there shouldn't be any issues. Do the players have different game objects?
es, they are in same update method, and, yes they have different game objects.But that shouldn't be a problem. Why do you think that is happening? @RobAnthem
Because when i changed the controls from arrow keys to numpad the problem is solved.
when you change rather than using arrows use other keys it works? probably i would say because your keys dont work properly? debug.log the exact time when you click at the keys and make sure that the arrows doont randomly stop being pressed/late pressed.
Answer by JonPQ · Feb 14, 2019 at 01:16 AM
if 'speed' is a public variable on a component...assuming for each player... make sure its the same on both. also check where this code is.... presumably in Update() not in OnGui() or anything that might get called more than once per frame.