Game Development Community

SetTransform at end of RayCast

by CTS · in Torque Game Engine · 10/30/2007 (2:30 pm) · 8 replies

Hello,

Ok I am using the code below to cast a ray and place an object at the end of that ray. Be it at the max distance if there was no collision or at the collision point if there was a collision. My problem is that the object at the end of the ray is jumping like it is not updated enough. the frame rate is fine it's just that the object seems to lag behind where I'm looking.

// Test to see if the user looks at the targets.
// The start of the Ray.
%RayStart = $CLIENT.player.getEyePoint();
%eyeVector = $CLIENT.player.getEyeVector();

// The end of the Ray
%RayEnd = VectorScale(VectorNormalize(%eyeVector),30);
%NewVector = VectorAdd(%RayEnd,%RayStart);

// Check for collision with the targets.
%CollID = containerRayCast(%RayStart,%NewVector,$TypeMasks::TerrainObjectType | $TypeMasks::InteriorObjectType | $TypeMasks::ShapeBaseObjectType | $TypeMasks::StaticShapeObjectType | $TypeMasks::StaticRenderedObjectType | $TypeMasks::StaticObjectType | $TypeMasks::StaticTSObjectType,$CLIENT.player);

Than I use setTransform on the object. I call all of this in the players.cc processtick() function.

Can anyone tell me why there is so much lag.

Thank you.

#1
10/30/2007 (3:31 pm)
The client renders objects in a different position from the server. Server objects are "Ghosted" to clients, and clients perform interpolation on them to try to keep them in sync with the server. The result of this is the rendered objects position lagging behind the server one.
#2
10/31/2007 (8:07 am)
Ok that makes sense. My next question is how do I get ride of the lag, heh. do I use the resolveObjectFromGhostIndex() function to get the "what I guess would be the client ID of the object" and use that ID to set its transform?

Thanks for the help I really appreciate it.
#3
10/31/2007 (8:30 am)
In the player's interpolateTick() method (or the object's interpolate tick method, if it has one) you need to interpolate the current RenderPosition for the object.

The Transform of an object is the current server state. The RenderTransform is the current client state of the object.

You are currently updating the server state. Now you need to update the client state.

To give you a hint, the client interpolates between -1.0 and 0.0 which means the client is always* one tick behind the server and is working to catch up.
I put an asterisk in the last statement to denote the fact that lag can cause the client to become in the lead. In this case you have to predict where you should be. I'm not quite that good yet: see my post "Network Frustrations".

Look at how the player keeps track of it's delta. It keeps track of the current server position and the difference between the last position and the current position. Then in interpolateTick it interpolates from -1.0 (the last position) to 0.0 (the current position). If there were lag we might even need to interpolate to 1.0 (one tick (32ms) past the current known server position) in which case we are only guessing that we are traveling a straight path.


This is all information I have learned myself in the last week working to correct the issues with Riding on Platforms as well as information gleaned from creating my GameCamera.
#4
10/31/2007 (1:30 pm)
Ok but I'm doing the setTransfrom and the raycast through script. By telling the object to setTransform shouldn't the client automatically interpolate where it needs to be?

My server/client knowledge is a bit lacking.
#5
10/31/2007 (3:08 pm)
Most likely not.

The problem probably stems from the object you are creating not keeping track of movement. For example, a Static Shape does not know where its been and WILL NOT interpolate.
#6
10/31/2007 (3:19 pm)
Ive been working on trying to add interpolation to staticshapes for awhile too(so i can have the player pic things up and carry them), i allready added it to the clientside tsstaticshapes along with animation, but i just cant get it to work on normal staticshapes, if someone does figure it out, let me know lol
#7
11/01/2007 (7:48 am)
I'm a bit confused because if I create a static shape in the world editor, select it and than drag it around the static shapes moves around fine. No jitters or jumping, it slides around like you would expect. So I took a look at how the editor handles this. All they do is call the objects setTransform(). If it works in the editor why not in script?

And thanks for all the help so far. Really helping me understand this so I can hopefully fix it.
#8
11/01/2007 (8:17 am)
The editor runs on the client side. It controls the client side copy of the object it is editing and runs at the frame rate of the client. No interpolation necessary.

The player's processTick method is run from the server, where you are modifying your object. The server ticks at a constant 32 milliseconds. Your object is only being updated (on the server, don't forget about lag between client & server) every 32ms. On the client you are probably updating every 16 ms or faster.