Game Development Community

Prevent Warping into Objects

by Ben Pagel · in Torque Game Engine · 11/04/2009 (12:48 am) · 0 replies

I've been working on implementing some changes to a warp code I had put into my game. Basically, the code allows the player to teleport 50 units in the direction they are facing. My problem becomes, that on occasions, this means the player teleports right into the middle of a wall, or half-way through a floor, and falls down or gets stuck.

Is there a simple way to prevent the player from teleporting into a collision object? I'm not even sure where to start. This is the code I'm using for the warp:

function serverCmdWarp1(%client)
{
	echo ("We be warping!");
	%avatar = %client.player;
	%playerEnergy = %avatar.GetEnergyLevel();
	echo("Energy level is " SPC %playerEnergy);
	if (%playerEnergy > 59)
	{
		%eyeVector = %avatar.GetEyeVector();
		echo ("eyeVector = " @ %eyeVector);
		%warpVector = vectorScale(%eyeVector,50);
		echo ("warpVector = " @ %warpVector);
		%currentPos = %avatar.getPosition();
		echo ("currentPos - " @ %currentPos);
		%newPos = vectorAdd(%currentPos, %warpVector);
		echo ("newpos = " @ %newPos);
		%currentTrans = %avatar.getTransform();
		echo ("currentTrans = " @ %currentTrans);
		%orientation = getWords(%currentTrans,3);
		echo ("orientation = " @ %orientation);
		%newTransform = %newPos SPC %orientation;
		echo ("newTransform = " @ %newTransform);
		%avatar.setTransform(%newTransform);
		%ppos = %avatar.getPosition();
		%x = getWord(%ppos, 0);
		%y = getWord(%ppos, 1);
		%z = getWord(%ppos, 2);
		%xx = getWord(%ppos, 3);
		%yy = getWord(%ppos, 4);
		%zz = getWord(%ppos, 5);
		%xyz = getWord(%ppos, 6);
		%terrpos = getTerrainHeight(%ppos);
			if (%terrpos > %z)
			{
				%avatar.setTransform(%x SPC %y SPC %terrpos + .5 SPC %xx SPC %yy SPC %xyz);
				warpTrail(%currentPos);
				warpTrail(%x SPC %y SPC %terrpos + 1 SPC %xx SPC %yy SPC %xyz);
				%avatar.setEnergyLevel(%playerEnergy - 60);
			} else {
				%avatar.setTransform(%x SPC %y SPC %z + .5 SPC %xx SPC %yy SPC %xyz);
				warpTrail(%currentPos);
				warpTrail(%x SPC %y SPC %z + 1 SPC %xx SPC %yy SPC %xyz);
				%avatar.setEnergyLevel(%playerEnergy - 60);
			}
		} else {
			echo("Energy is too low");
		}
}

Any suggestions?

About the author

Recent Threads

  • Timed Score Increase