May 23, 2012, 01:19:42 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: Please report any bugs or issues that you might be encountering with the Beta in the Support System so that we can better keep track of any oustanding issues that may come up.

GameCore Support System
 
   Home   Help Search Login Register  
Pages: 1 [2]
  Print  
Author Topic: FPS Flashlight example  (Read 1578 times)
Ransom
Full Member
***
Posts: 132



View Profile
« Reply #15 on: September 06, 2008, 10:32:35 PM »

Since the light is loaded by the player's opr, it will follow the rotation of the player with no effort from us.  However, since our player only rotates left and right we need to manually set the vertical (or Up Down) rotation.  The character.gsl is already tracking this for the camera, so all we need to do is access that info.

Inside...
Quote
bool HandleEvent( Object@ object, const String& in event, GameEventParams@ params)
{

You need the following (which should already be in your character.gsl, unless you've changed it.  The comments are added by me to help explain how this works.
Quote
   if (params.stringValue == "MouseRelativeX")
      {
         lookLeftRight += params.floatValue * mouseMult;
         return true;
      }
      if (params.stringValue == "MouseRelativeY")
      {
         lookUpDown -= params.floatValue * mouseMult;
         if (lookUpDown < -85)
            lookUpDown = -85;
         if (lookUpDown > 85)
            lookUpDown = 85;
         return true;
                }
/*  MouseRelativeX and Mouse RelativeY should be declared in input.cfg.  As their names imply, they track the mouse's movement

lookLeftRight is a variable float declared at the top of the script.  This will store where MouseRelativeX is. 
mouseMult is a const float also declared at the top.  mouseMult = 180/PI converts the params given by MouseRelativeX and Y to degrees
lookUpDown is also a variable float decared at the top of the script.  This will store where MouseRelativeY is.

Basically, what this section does is track the mouse's movement, and then limit the vertical mouse movement to only 85 degrees up or down. */
      

So now we just grab our light and access the vertical mouse movement stored in "lookUpDown" to set our light's rotation.
Quote
   Light@ light = object.GetLight("Flashlight");
   light.SetRotationEuler(Vector( 0, 180 + lookUpDown , 0));

/*  180 + lookUpDown is used to invert the rotation of the light.  Just using lookUpDown without inverting it, causes the light to go down when you go up and vice versa.  We don't set the X or Z of the rotation because the light is automatically following the player's rotation for those axis  */

I hope that helped explain things some.   Tongue

Logged
Squat
Hero Member
*****
Posts: 592


View Profile
« Reply #16 on: September 06, 2008, 11:37:50 PM »

Thanks Ransom, that explains quite a lot.
Logged
gekido
Guest
« Reply #17 on: September 07, 2008, 11:48:42 PM »

the lag is the shader being compiled - gamecore selects and compiles the shaders used by scenes on the fly (which saves us from having a lengthy pre-compile at the start of your game).  there are a couple of solutions - one is to have at least one other shadowmap-enabled light in the scene in addition to the flashlight (or to turn the flashlight on by default) - the second is to disable the shadowmap on the light.
Logged
Pages: 1 [2]
  Print  
 
Jump to:  

 
Powered by MySQL Powered by PHP bluBlur Skin © 2006, hbSkins
Powered by SMF 1.1.14 | SMF © 2006-2011, Simple Machines LLC
Valid XHTML 1.0! Valid CSS!