Server Moving Independantly from Client
by Griffin Milsap · in Torque Game Engine · 05/14/2006 (10:36 am) · 3 replies
I'm using a modified version of the pathshape resource to create an object which recieves a new position from an ouside class each tick and interpolates to that position.
I have a few variables which are accessable from the script/console that change the speed and or position of the vehicle relative to the path its following.
When I change the speed of the vehicle in the console, and enter the mission editor, the little red dot which represents the vehicle moves at the correct speed, where as the shape that is visible from outside the mission editor isnt moving at the same speed as the dot.
I investigated it further, and found out that my process tick function is being called twice. Once from the server, and once from the client. When the server calls the process tick, it's speed variable reads correctly, but when its called from the client, its speed variable hasn't been modified from the console function I called earlier, and it keeps updating at the old speed.
Any idea how I can fix this?
-Griff
Edit: It appears that it creates an object of the pathshape for the server and an object for the client.
When I call the function which allows me to change speed, it changes the speed on the server object and not on the client object.
I call it like so:
I use %this.car.setSpeed(2); to change the speed, and setSpeed is a function defined in PathShape.
How do I call the function on the client object?
I have a few variables which are accessable from the script/console that change the speed and or position of the vehicle relative to the path its following.
When I change the speed of the vehicle in the console, and enter the mission editor, the little red dot which represents the vehicle moves at the correct speed, where as the shape that is visible from outside the mission editor isnt moving at the same speed as the dot.
I investigated it further, and found out that my process tick function is being called twice. Once from the server, and once from the client. When the server calls the process tick, it's speed variable reads correctly, but when its called from the client, its speed variable hasn't been modified from the console function I called earlier, and it keeps updating at the old speed.
Any idea how I can fix this?
-Griff
Edit: It appears that it creates an object of the pathshape for the server and an object for the client.
When I call the function which allows me to change speed, it changes the speed on the server object and not on the client object.
I call it like so:
%pulseflyer = new PathShape() {
dataBlock = LoopingShape;
// set position to whatever suits your needs...
position = %spawnPoint;
};
//Cleanup
MissionCleanup.add(%pulseflyer);
//give it a name
%pulseflyer.setShapeName(%this.name);
%this.car = %pulseflyer;where %this is the client objectI use %this.car.setSpeed(2); to change the speed, and setSpeed is a function defined in PathShape.
How do I call the function on the client object?
About the author
#2
05/14/2006 (11:12 am)
Bleh nevermind. =P
#3
I'm doing my homework right now, but I'll try what you said in a bit, and see if it works.
Thanks for the fast reply!
-Griff
Edit: It worked!
Thanks a ton!
05/14/2006 (11:54 am)
Alright. I had no idea that you had to do that when working with network objects.I'm doing my homework right now, but I'll try what you said in a bit, and see if it works.
Thanks for the fast reply!
-Griff
Edit: It worked!
Thanks a ton!
Associate Orion Elenzil
Real Life Plus
but i'll wager that you have to have a method for the speed variable to be transmitted from the server to the client; it doesn't happen automatically.
.. which probably means you'll want to modify the packUpdate() and unpackUpdate() methods of whatever object it is that contains the speed variable.
it'll be something like:
1. add a new netMask, or find one that you can override.
2. make a "setter" method for speed which does something like:
void setSpeed(F32 val) { mSpeed = val; setMaskBits(myNetMask); }3. in packUpdate for the object, something like this:
... if (stream->writeFlag(mask & myNetMask)) { stream->writeFloat(mSpeed, 7); // 7 is how many bits of precision you want. } ...4. in unpackUpdate for the object, something like this:
... if (stream->readFlag()) { // it's myNetMask mSpeed = stream->readFloat(7); // 7 needs to match the 7 from writeFloat, obviously. } ...- note, it's _critical_ that the writeMask/writeFloat and the readMask/readFloat go in exactly the same position in the bitstream. This means take some time to find some item in the bitstream which you can clearly identify in both packUpdate and unpackUpdate, and insert your new bits before that item in both routines. (Or after, just be consistent).
hopefully i understood your issue right and this can help you out.