Game Development Community

Rooting the player in one spot

by Tyler Pfaff · in Torque Game Engine · 10/29/2004 (3:47 pm) · 8 replies

Hello all,

I'm attempting to root the player in one place as long as the right mouse button is being held down. With some experimenting I've managed to stop their movement by moving them in all directions then setting the $movementSpeed variable to 0. Sadly once they release the button they begin to move in the last direction I moved them in. If I don't move the player then even after setting $movementSpeed to 0 the player will continue to move in the direction they're holding.

I need to reliably halt the player no matter how they are moving, then return control to normal as soon as they release the Right mouse button.

Here's the code I'm using right now:

// This is called when the Rmouse button is clicked
function Player::SetSpecial(%this)
{
%this.client.player.playerSpecial = 1;
%this.client.player.CheckSpecial();
}


function Player::CheckSpecial(%this)
{
if (%this.client.player.playerSpecial == 1)
{
switch(%this.client.player.playerType)
{
case 0:
echo("You are a Knight!");
// Stop the player from moving, one way or another
%this.client.player.StopPlayer();
case 1:
echo("You are an Archer!");
case 2:
echo("You are a Jester!");
case 3:
echo("You are a Friar!");
}
%this.client.player.playerSpecial = 0;
%this.schedule(1000, CheckSpecial);
}
else
{
// return values to normal
switch(%this.client.player.playerType)
{
case 0:
%this.client.player.UnStopPlayer();
case 1:
case 2:
case 3:
}
}
}

function Player::StopPlayer(%this)
{
moveright(48 * 90);
moveleft(48 * 90);
movebackward(48 * 90);
moveforward(48 * 90);
$movementSpeed = 0;
moveMap.bind( keyboard, a, EmptyFunction );
moveMap.bind( keyboard, d, EmptyFunction );
moveMap.bind( keyboard, w, EmptyFunction );
moveMap.bind( keyboard, s, EmptyFunction );
moveMap.bind( keyboard, space, EmptyFunction );
moveMap.bind( mouse, xaxis, EmptyFunction );
moveMap.bind( mouse, yaxis, EmptyFunction );
}

function Player::UnStopPlayer(%this)
{
moveMap.bind( keyboard, a, moveleft );
moveMap.bind( keyboard, d, moveright );
moveMap.bind( keyboard, w, moveforward );
moveMap.bind( keyboard, s, movebackward );
moveMap.bind( keyboard, space, jump );
moveMap.bind( mouse, xaxis, yaw );
moveMap.bind( mouse, yaxis, pitch );
$movementSpeed = 1;
}

function Player::EmptyFunction(%this)
{
// i don't do anything!!
}

Please help!

thanks

#1
10/29/2004 (3:49 pm)
If you're developing a single player game, this would work for some time until someone manages to hack it.

If you EVER are going to make it multiplayer, then I would totally revise your method.. it's clientside and thus the client can be modified or packet spoofed to never be rooted.
#2
10/29/2004 (4:36 pm)
This game is multiplayer, but I'm not worried about hacking right now. The main problem is that this isn't working.

Any suggestions?
#3
10/29/2004 (6:47 pm)
If it's possible to save the initial movement of the player, what about resetting that movement after the other move*direction* statements and immediately prior to the setting the movement speed to zero?

When continuing, maybe the player will be moving in the initial direction.
#4
10/29/2004 (7:03 pm)
Man, what a mess. First off...

function Player::SetSpecial(%this)
{
%this.client.player.playerSpecial = 1;
%this.client.player.CheckSpecial();
}


should be


function Player::SetSpecial(%this)
{
%this.playerSpecial = 1;
%this.CheckSpecial();
}


because %this.client.player == %this


next..

function Player::CheckSpecial(%this)
{
	if(%this.playerSpecial == 1)
	{
		switch(%this.playerType)
		{
			case 0:
			
				echo("You are a Knight!");
				// Stop the player from moving
				%this.StopPlayer();
				
			case 1:
			
				echo("You are an Archer!");
			
			case 2:
			
				echo("You are a Jester!");
			
			case 3:
			
				echo("You are a Friar!");
			
		}
		
		%this.playerSpecial = 0;
		%this.schedule(1000, CheckSpecial);
	}
	else
	{
		// return values to normal
		switch(%this.playerType)
		{
			case 0:
			
				%this.UnStopPlayer();
			
			case 1:
			
			case 2:
			
			case 3:
			
		}
	}
}



Now lastly...

function Player::StopPlayer(%this)
{
	setSpeed(0);
	
	moveforward();
}
  
 
  
 
function Player::UnStopPlayer(%this)
{
	setSpeed(1);
}


You should be able to tell where you went wrong by looking at that.
#5
10/29/2004 (7:15 pm)
Gonzo I'm trying to do generally the same thing - stop a player from moving for a set time period. When I do setSpeed(0);, nothing happens. How does this work?

btw - sup tyler
#6
10/30/2004 (3:02 am)
You're probably going to have to muck around in the player's updatePos method in the C++ code and have it lock to a position till you release it...
#7
10/30/2004 (7:16 am)
Thanks for the help Gonzo, I fixed it now. I also had to schedule the unStop so that the player would stay rooted during the wait time, code change was:

%this.schedule(1000, UnStopPlayer);

vs

UnStopPlayer();
#8
11/02/2004 (10:22 pm)
Another way of doing this:

datablock StaticShapeData(Anchor)
{
   dummy = true;
};
function Player::FreezePlayer(%this)
{
   if(isObject(%this.Blocker))
   {
       %this.setControlObject(-1);
       %this.Blocker.delete();
       %this.Blocker = -1;
   }
   else
   {
       %this.Blocker = new StaticShape()
       {
         Datablock = Anchor;
         Position = %this.Position;
       };
       %this.setControlObject(%this.Blocker);
   }
}