Game Development Community

Setting a player's aim directly

by Glen Rosenblatt · in Torque Game Engine · 04/27/2004 (11:26 am) · 8 replies

Hi all,

I am posing a question concerning the Player's aim vector. My game requires me to set it explicitly based on the mouse location (Think SOLDAT). I know that I can set the $mvPitch to a value and have it alter the aim but the problem is that the changes are applied each frame and then $mvPitch gets set back to 0. I need to find a solution where I can set the $mvPitch (or something else maybe) to a value and have that be the aim vector. Has anyone done anything like this before? Thanks in advance for any replies.

#1
04/27/2004 (11:53 am)
Hope you find a solution to this if you're planning to do something along the lines of SOLDAT :D it rocks.
#2
04/27/2004 (11:59 am)
Stefan: yep actually the game is nearly identical to Soldat, except ... different :)
#3
04/27/2004 (12:00 pm)
Lol that's one of the games that can make anyone laugh in multiplayer. we had sessions of over 14 at once in LAN and that was huge fun.

sorry for going offtopic though. good luck :)
#4
04/27/2004 (12:04 pm)
No problem, it's a good feeling to know that people will enjoy the game once it is completed.
#5
04/30/2004 (4:55 am)
Not that anyone was paying attention anyway :) but i've completed this task on my own.
#6
05/02/2004 (11:33 pm)
This function initially works, it will update the player's aim to the angle from the center of the screen to the mouse position. the problem is, when you die and respawn and the cursor is on the left of the player, it will swap (what i mean is, if the cursor is on the left of the player you will aim right, and vice versa). if your cursor is on the right side of the player when you respawn, this does not occur.

function updateAim()
{
	%extent = canvas.getExtent();
	%cx = firstWord(%extent);
	%cx = %cx / 2;
	%cy = getWord(%extent, 1);
	%cy = %cy / 2;
	%mpos = canvas.getCursorPos();
	%mx = firstWord(%mpos);
	%my = getWord(%mpos, 1);

	%dirD = 0.0;
	%dir = 0.0;
	if( %mx > %cx )	{
		%dir = mAtan( (%my - %cy), (%mx - %cx) );
		%dirD = mRadToDeg( %dir );
		$faceDir = "Right";
	}	else {
		%dir = mAtan( (%mx - %cx), (%my - %cy) );
		%dirD = mRadToDeg( %dir );
		%dirD = %dirD + 90.0;
		%dir = mDegToRad(%dirD);
		$faceDir = "Left";
	}
	%headRot = player().getHeadRotation();
	%finalRot = %dir - %headRot;
	$mvPitch = %finalRot;
	
	if( ($oldDir !$= $faceDir) )
	{
        	switch$($faceDir)
		{
	        	case "Right":
		        	$mvYaw = mPI();
				$oldDir = "Right";
			case "Left":
				$mvYaw = mPI();// * -1;
				$oldDir = "Left";
		}
	}
}
#7
03/08/2006 (6:40 pm)
I'm trying to figure out how to implement this here if anyone has some insight!

Thanks,
Matt
#8
06/01/2006 (8:55 am)
Have you found a solution to the left/right swapping issue yet?