Opinions about this code
by Carlos Beltran · in Torque 3D Professional · 03/01/2011 (8:19 am) · 2 replies
Hi
I want to make a multiplayer game with the camera that use the game DeathSpank, So I added the following code in the function GameCore::preparePlayer(%game, %client) in the gameCore.cs
Besides, I Changed the function moveleft(%val)and the others in default.bind.cs for this:
In my server scripts I have this:
in the file commands.cs:
in the file player.cs
I want to know if my code is ok, or there is another and better way to do it.
Thanks in advance
I want to make a multiplayer game with the camera that use the game DeathSpank, So I added the following code in the function GameCore::preparePlayer(%game, %client) in the gameCore.cs
%game.spawnPlayer(%client, %playerSpawnPoint, false); %client.camera.setOrbitObject($SpawnObject, mDegToRad(50) @ " 0 0", 0, 20, 20);.
Besides, I Changed the function moveleft(%val)and the others in default.bind.cs for this:
function moveleft(%val)
{
commandToServer('Move','LEFT', %val);
}In my server scripts I have this:
in the file commands.cs:
function serverCmdMove(%client, %dir, %pressed){
%client.player.move( %dir, %pressed );
}in the file player.cs
$moving = false;
$moveDirection = "";
$moveQuantity = 5;
function Player::move(%player, %dir, %pressed )
{
%dir = getWord( %dir, 1);
if ( $moving )
{
if ( ! %pressed && %dir$= $moveDirection )
{
$moving = false;
}
}
else
{
if ( %pressed )
{
$moving = true;
$moveDirection = %dir;
%player.schedule(100, "moveUpdate");
}
}
}
function Player::moveUpdate(%player)
{
%pos = %player.getPosition();
switch$( $moveDirection )
{
case "LEFT":
%player.setMoveDestination( VectorAdd( %pos, -$moveQuantity @ " 0 0") );
case "RIGHT":
%player.setMoveDestination( VectorAdd( %pos, $moveQuantity @ " 0 0") );
case "UP":
%player.setMoveDestination( VectorAdd( %pos, "0 " @ $moveQuantity @ " 0") );
case "DOWN":
%player.setMoveDestination( VectorAdd( %pos, "0 " @ -$moveQuantity @ " 0") );
}
if ( $moving )
%player.schedule(100, "moveUpdate");
}I want to know if my code is ok, or there is another and better way to do it.
Thanks in advance
About the author
#2
Thank you very much for your reply, I am going to change the way I am doing the movement and the way I set the camera.
Any comments and suggestions are welcomed,
03/02/2011 (6:21 am)
Ouchh,Thank you very much for your reply, I am going to change the way I am doing the movement and the way I set the camera.
Any comments and suggestions are welcomed,
Torque Owner Davide Archetti
Default Studio Name
First, you don't need to send the move to the server, this is already done inside the engine.
Second, I don't know DeathSpank, but looking at the trailer it just seems to use a third person camera view, and this is already in the engine, you have just to adjust the nodes in the model, if you want to have the third person camera far away from the player. This could be done also in script, although I don't remember if this is a mod I made, or stock engine functionality ;) ... well, perhaps you can do it also in the shape editor