Making A New Player-Like Client-Controlled Class?
by William Lee Sims · in Torque Game Engine · 09/07/2008 (7:42 pm) · 6 replies
I'm trying to make the existing Player class move along highly detailed splines (with the Z-coordinate changed so the player follows the ground). I've tried several things, all unsuccessfully, and am feeling lost and confused. (At least the playing around has led to better understanding of the Player class.)
My current plan is to do the following:
1) Copy the Player class to HeroPlayer.
2) The client will pick a "path" and send that to the server.
3) The server will tell all clients that "Player Bill" will travel along "Spline X".
4) The server will do nothing with position (or update the position to the end of the spline).
5) The clients will be busy doing the real calculations
5) A) Update the heading and position based upon the spline, "dropping" the player down to the ground.
5) B) Footprints/sounds/etc.
5) C) Ignoring collision with other players (who might be moving on the path in the opposite direction).
First, is there a better way? I'm open to any suggestion.
It looks like the server does so much, though. Is it all really necessary? Just looking at "packUpdate()" terrifies me... the server sends the animations, position, and speed. The "unpackUpdate()" handles interpolation (which seems meaningless under my changes).
Also, do you think this will work? I'm going to start down this path, but I'd like to hear from those more experienced with the engine.
Finally, will this mess up the Advanced Camera resource? I'm using it for the orbit camera, but I feel like it also does stuff on both the client and server side and I'm worried I'll have to re-write it, too.
My current plan is to do the following:
1) Copy the Player class to HeroPlayer.
2) The client will pick a "path" and send that to the server.
3) The server will tell all clients that "Player Bill" will travel along "Spline X".
4) The server will do nothing with position (or update the position to the end of the spline).
5) The clients will be busy doing the real calculations
5) A) Update the heading and position based upon the spline, "dropping" the player down to the ground.
5) B) Footprints/sounds/etc.
5) C) Ignoring collision with other players (who might be moving on the path in the opposite direction).
First, is there a better way? I'm open to any suggestion.
It looks like the server does so much, though. Is it all really necessary? Just looking at "packUpdate()" terrifies me... the server sends the animations, position, and speed. The "unpackUpdate()" handles interpolation (which seems meaningless under my changes).
Also, do you think this will work? I'm going to start down this path, but I'd like to hear from those more experienced with the engine.
Finally, will this mess up the Advanced Camera resource? I'm using it for the orbit camera, but I feel like it also does stuff on both the client and server side and I'm worried I'll have to re-write it, too.
#2
09/08/2008 (6:42 am)
Yeah I think you might have an easier time by looking at the existing path system and improving it to use splines.
#3
1) Modified AIPlayer class to have pack/unpackUpdate() functions.
1) A) It has 3 "States" for update: StateMask, DestinationMask, and AimMask.
1) B) MoveState/MoveSpeed/MoveTolerance are under StateMask
1) C) MoveDestination/MoveSlowdown are under DestinationMask
1) D) AimLocationSet/AimLocation/AimOffset are under AimMask (no AimObjects are needed for my game).
2) Set the "States" whenever the appropriate variables changed (obviously).
3) Modified Player::processTick() from
Now when I use the AIPlayer's setMoveDestination script function, everything is smooth and nice.
I'm still shaky on what do to with my splines. My current plan will be the following:
1) Modify AIPlayer to have a "Splined Desination".
2) Modify AIPlayer's getAIMove to get my next position on the spline at TickSec's in the future and make that my MoveDestination.
3) Find where extrapolation is happening and hope that I can modify this to use the spline, too. Scary thoughts inserted here.
Please, if anybody has more ideas/suggestions/comments, let me know. I'm still not thrilled with the way it's going, especially since I still have to modify the Player class anyway (to not collide with other players and as described in this post).
09/08/2008 (12:55 pm)
Originally, I dismissed using the AI Player because of the jerkiness in tracking it with an orbit camera. But I made the AIPlayer start working with following modifications:1) Modified AIPlayer class to have pack/unpackUpdate() functions.
1) A) It has 3 "States" for update: StateMask, DestinationMask, and AimMask.
1) B) MoveState/MoveSpeed/MoveTolerance are under StateMask
1) C) MoveDestination/MoveSlowdown are under DestinationMask
1) D) AimLocationSet/AimLocation/AimOffset are under AimMask (no AimObjects are needed for my game).
2) Set the "States" whenever the appropriate variables changed (obviously).
3) Modified Player::processTick() from
if (!move && isServerObject() && getAIMove(&aiMove)) move = &aiMove;to
if( getAIMove( &aiMove ) ) move = &aiMove;which forces to Player to always get the AIMove on both the server and the client. This keeps the movement more in sync.
Now when I use the AIPlayer's setMoveDestination script function, everything is smooth and nice.
I'm still shaky on what do to with my splines. My current plan will be the following:
1) Modify AIPlayer to have a "Splined Desination".
2) Modify AIPlayer's getAIMove to get my next position on the spline at TickSec's in the future and make that my MoveDestination.
3) Find where extrapolation is happening and hope that I can modify this to use the spline, too. Scary thoughts inserted here.
Please, if anybody has more ideas/suggestions/comments, let me know. I'm still not thrilled with the way it's going, especially since I still have to modify the Player class anyway (to not collide with other players and as described in this post).
#4
09/12/2008 (3:20 pm)
I'm just getting started, but I have a need for somethign similar so I'll let you know if come up with anything good.
#5
09/12/2008 (6:26 pm)
I've made it work, but I've only tested it in a single-player configuration. I'm going to be testing multi-player today. While I think it will just work, I want to make sure before I let people know where I am on this.
#6
1) Copy the Player class to HeroPlayer.
2) The client ("Player Bill") will pick a path and send that to the server.
3) The server will tell "Player Bill" to follow that path.
4) The server will move the player along the spline and only send it to non-"Player Bill" connections.
5) The "Player Bill" client will do the real calculations like the server is doing.
I dread making so many changes, but I have a feeling that this will work and be smooth.
09/13/2008 (6:14 pm)
My multi-player test showed that the remotely-connected clients are choppy. My newest plan is much like my first:1) Copy the Player class to HeroPlayer.
2) The client ("Player Bill") will pick a path and send that to the server.
3) The server will tell "Player Bill" to follow that path.
4) The server will move the player along the spline and only send it to non-"Player Bill" connections.
5) The "Player Bill" client will do the real calculations like the server is doing.
I dread making so many changes, but I have a feeling that this will work and be smooth.
Torque Owner kc_0045