Game Development Community

Problem with Player Movement script.

by J.T. Ooley · in Torque Game Builder · 08/31/2010 (4:56 am) · 2 replies

Hey guys,
I'm working on a topdown shooter which uses the mouse to fire. I'm trying to get the player's ship to face the direction it's moving while using the 'WASD' keys, but face the mouse when it's clicked to fire (being able to move freely but facing the mouse). The WASD key movement facing was working fine until I added the: if($FiringWeaponActive = true) statement bellow. After I added that, the facing worked just like it's supposed to while firing. However, the ship will always face the mouse even when when there's no mouse click. I've tried everything I can think of (I'm fairly new to torquescript) and lurked for awhile to see if I could get an idea on the forums, but couldn't find anything. Is there a way to override the OnUpdate function durring a mouse click?
function PlayerMovementBehavior::OnUpdate(%this)
{
   %angle = mRadtoDeg(maTan(%this.controlsX,%this.controlsY));
   if(%this.controlsX != 0 || %this.controlsY != 0)
   {
      if($FiringWeaponActive = true)
      {
         %ProjectileAngle = GetProjectileAngle();
         Ship.turnSpeed = 200.0;
         Ship.rotateTo(%ProjectileAngle,ship.turnSpeed,true,false,true,0.1);
      }
      if($FiringWeaponActive = false)
      {
         %this.owner.rotateTo(%angle,%this.turnspeed);
      }
      %this.owner.setImpulseForcePolar(%angle,%this.acceleration);
   }
}

function PlayerMovementBehavior::GetProjectileAngle()
{
   %vec = t2dVectorSub(Ship.getPosition(),SceneWindow2D.getMousePosition());
   return -mRadToDeg(mATan(getWord(%vec,0),getWord(%vec,1)));
}

function PlayerMovementBehavior::onMouseDown(%this,%modifier,%worldPosition,%mouseClicks)
{
   $FiringWeaponActive = true;
}

function PlayerMovementBehavior::onMouseUp(%this,%modifire,%worldPosition,%mouseClicks)
{
   $FiringWeaponActive = false;
}

#1
08/31/2010 (8:13 am)
if($FiringWeaponActive ##=## false)

Might want to change that to a logical comparison operator (==) rather than using the assignment operator.
#2
08/31/2010 (8:25 am)
Awesome, that fixed it. Thanks