Page 1 of 1

Strange results locally vs. on an offsite server

PostPosted: Tue Dec 09, 2014 4:10 am
by cdiddy2
So I am getting some very strange results where when I run the game locally(done on various computers) I get different results than when I run the game on a rented server. So basically when the user presses up, the character is supposed to fly upward a little bit. But when I run it on the server the player flys way higher than they do when I run the server on my local machine.

Code: Select all
this._box2dBody.SetLinearVelocity(new IgePoint(0, 0, 0));
var movementVector = new ige.box2d.b2Vec2(0, -800);
this._box2dBody.ApplyImpulse(movementVector, this._box2dBody.GetWorldCenter());


That is the code used to launch the player upward. Seems pretty straight forward but on the server I have to change the movement vector to
Code: Select all
new ige.box2d.b2Vec2(0, -140);
To Get the same results that I get when I run it locally

Anyway really strange. Anyone know what could be up here?

Re: Strange results locally vs. on an offsite server

PostPosted: Tue Dec 09, 2014 12:16 pm
by TheBenji
What do you mean by locally? Do you run the server on your local machine or do you mean local as in clientside?

Either way you probably need to take the time in account. I guess you put it into a Entity behaviour method that gets called every tick, right?
Depending on how fast the server is this might vary. Just multiply your number with deltaT and then it should work the same no matter how fast the server runs.

Re: Strange results locally vs. on an offsite server

PostPosted: Thu Dec 11, 2014 1:05 am
by cdiddy2
Sorry I meant running the server on my computer vs. running it on a rented virtual private server. Gets different results running on one or the other.

Ok I can try taking the tick delta into account. The weird thing is I am not taking the tick delta into account at other places where I do this exact same thing but there is no difference in other cases. I'll look for other differences too.

Re: Strange results locally vs. on an offsite server

PostPosted: Fri Dec 19, 2014 12:57 am
by cdiddy2
TheBenji wrote:Just multiply your number with deltaT and then it should work the same no matter how fast the server runs.


So like this? ige._tickDelta*-20. Thats the value to get it to run nice when I run the server on my local machine. But on the server this launches them way to high like what was happening before.

Re: Strange results locally vs. on an offsite server

PostPosted: Tue Dec 23, 2014 1:02 am
by rob
When you press up on the keyboard are you sending a state to the server eg: player 1 up = true
Then when the user lets go of the up key are you sending the new state eg: player 1 up = false

?

If instead you are reacting to each key press instead of a state change that can cause the effect you are talking about...

Re: Strange results locally vs. on an offsite server

PostPosted: Wed Dec 24, 2014 4:56 am
by cdiddy2
rob wrote:When you press up on the keyboard are you sending a state to the server eg: player 1 up = true
Then when the user lets go of the up key are you sending the new state eg: player 1 up = false

?

If instead you are reacting to each key press instead of a state change that can cause the effect you are talking about...


I am using the same input as the multliplayer example 24.2
if (ige.input.actionState('left') || ige.input.actionState('a')) {
if (!this.controls.left) {
// Record the new state
this.controls.left = true;
// console.log(this._id);

// Tell the server about our control change
ige.network.send('playerControlLeftDown');
}


where the network command sets the state on the server.

Re: Strange results locally vs. on an offsite server

PostPosted: Thu Dec 25, 2014 11:01 am
by rob
I think the first response was correct, you need to multiply your movement by the tick delta:

Code: Select all
new ige.box2d.b2Vec2(0 * ige._tickDelta, -140 * ige._tickDelta);


Tick delta is usually around 16 so whatever movement you wanted (e.g. 140) you should divide by 16 first when you hard-code it:

140 / 16 = 8.75 (call it 8 for easy calc)

So do:

Code: Select all
new ige.box2d.b2Vec2(0 * ige._tickDelta, -8 * ige._tickDelta);

Re: Strange results locally vs. on an offsite server

PostPosted: Sat Dec 27, 2014 3:55 am
by cdiddy2
So the tick delta when I run the server locally is around 30 and the Y number I use -800. The tick delta when I run the server on the virtual private server is around 17 and the Y number I use is around 140.

800/30=26.66
140/17=8.24

This means that I need to create a non linear function to get these numbers to work out. That seems way to hacky of a way to get this fixed.

Re: Strange results locally vs. on an offsite server

PostPosted: Sat Dec 27, 2014 10:08 am
by TheBenji
No, just hardcode it with 8 and see if that works out for you on both.

Your computer execute the code on different speed, your server is just faster(/better) than your local PC thus the update method gets called more often.
The tickDelta basically just says how much time went by since the last time the update method got called.
So if you mulitply your number with tickDelta you always get the same number over a certain time frame, if that makes sense for you.

Re: Strange results locally vs. on an offsite server

PostPosted: Sat Dec 27, 2014 10:44 pm
by cdiddy2
Ah, that is very close. There is still slight difference between the two but not too much. There is a platform I test with to see if I can jump up onto it. I can easily make it on the external server but rarely make it when I run the server locally. Any idea why that slight difference would be there or why there is some variability in the jump heights, i.e. sometimes locally I can make it onto the platform but only rarely. Is that just because the tickDelta changes?