Search Unity

RTS to FPS switching

Discussion in 'Scripting' started by homeworld, Jan 27, 2012.

  1. homeworld

    homeworld

    Joined:
    Aug 15, 2010
    Posts:
    14
    Hi all,

    I create a strategy and want to learn the best way how to implement switching RTS mode to FPS and back.

    For example: I choose my unit, pressed F button and now i can see control unit like FPS, pressed F again and go back to RTS mode.

    Thnx.

    P.S. Sorry for my english.
     
  2. markusb

    markusb

    Joined:
    Mar 20, 2010
    Posts:
    157
    I would give every unit a disabled camera. When you press "f", you disable the rts-camera and enable the one with the unit.
     
  3. homeworld

    homeworld

    Joined:
    Aug 15, 2010
    Posts:
    14
    Ok, but with this way u can only change camera view, but what about control system ?

    I mean in RTS ur mouse move camera, select units etc. but if i just change camera i can't shoot, move etc. in FPS mode, so i think i must disable RTS scripts that responsible for RTS action and enable FPS scripts, but how to do it right ?
     
  4. wolfhunter777

    wolfhunter777

    Joined:
    Nov 3, 2011
    Posts:
    534
    You could use game states to trigger what runs what. Could get messy if you combine everything into one script (which is what I do but I manage them properly). If you need to disable a script, just set that script enabled to false. If you want to use the script, make sure the enabled is true.
     
  5. aubergine

    aubergine

    Joined:
    Sep 12, 2009
    Posts:
    2,880
    You save the eye position(this should be standart for your units) and lerp the camera position according to the controlled unit and/or the top view.
    EDIT: You also indicate which character controller or transform(whatever your units use) to be controlled by the script.
     
  6. homeworld

    homeworld

    Joined:
    Aug 15, 2010
    Posts:
    14
    Ok, thnx to all for answers i'll try it later post results.
     
  7. Nems

    Nems

    Joined:
    Jul 18, 2011
    Posts:
    65
    Hi,
    Just an impro :

    Code (csharp):
    1. public class ModeSwitcherScript : MonoBehaviour {
    2.    
    3.     private int CurrentMode = 0; // 0 : rts ; 1 : fps
    4.    
    5.     // Other var
    6.    
    7.     // Use this for initialization
    8.     void Start () {
    9.         // Init
    10.     }
    11.    
    12.     // Update is called once per frame
    13.     void Update () {
    14.         //1) Switch mode procedure
    15.         // If a unit is selected and 'F' is pressed
    16.         // Then invert CurrentMode
    17.        
    18.         if("If a unit is selected and 'F' is pressed")
    19.         {
    20.             CurrentMode = CurrentMode == 0 ? 1 : 0;
    21.                        
    22.             switch(CurrentMode)
    23.             {              
    24.             case 1: // RTS -> FPS
    25.                 // Disable RTS scripts
    26.                 // Enabled FPS scripts (FPS controller...)
    27.                 // Move camera to unit's head pos/ori using interpolation
    28.                 break;
    29.                
    30.             case 0: // FPS -> RTS
    31.                 // Disabled FPS scripts (FPS controller...)
    32.                 // Enable RTS scripts
    33.                 // Move camera on top of unit adn adjust rotation as you prefer
    34.                 break;
    35.             }
    36.         }
    37.        
    38.         //2) CurrentMode ?
    39.         switch(CurrentMode)
    40.         {
    41.         case 0: // RTS
    42.             RunRTSstuff();
    43.             break;
    44.            
    45.         case 1: // FPS
    46.             RunFPDstuff();
    47.             break;
    48.         }
    49.     }
    50. }
     
  8. homeworld

    homeworld

    Joined:
    Aug 15, 2010
    Posts:
    14
    Thnx Nems :)