Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice
  2. Ever participated in one our Game Jams? Want pointers on your project? Our Evangelists will be available on Friday to give feedback. Come share your games with us!
    Dismiss Notice

Realistic FPS Prefab [RELEASED]

Discussion in 'Assets and Asset Store' started by Deleted User, Apr 5, 2013.

  1. Defcon44

    Defcon44

    Joined:
    Aug 19, 2013
    Posts:
    400
    Hey Tony,

    I have a little problem with you'r health bar, i don't know if this problem will be report last month, so sorry if i make a post with a fixed problem.

    i have replace the code, make a slider (create a canvas etc) but the bar don't work, she stay white :/
    I have clic on the "Health text(clone)" and the hitpoint move when i take damage but the progress don't change :s
    The Layer is UI.

    Any idea ?

    Thanks
     
  2. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    10,483
    Hi @Baraff - There's very little technical difference between competitive and co-op; it's just who is allowed to shoot whom. 2 players via a connection would be easier to implement in RFPS than 2 players on the same machine. This is because the RFPS scripts assume that there's only one first person player in the scene. With split screen, you'd have two fps players in the scene. You'd have to make major changes to RFPS's scripts to handle this.

    One advantage of co-op is that cheating is less of a concern, so you can get away with a non-authoritative server. If you're handy with Unity's new networking, you can follow the same idea as my Bolt instructions.

    Hi @Defcon44 - Your slider must be named "Healthbar" The spelling and capitalization must be exact.
     
  3. Baraff

    Baraff

    Joined:
    Aug 16, 2014
    Posts:
    251
    Thanks, as always @TonyLi. I

    I understand your points. I am kind of hoping I can avoid the need for split screen but it will take some convincing of others.
    Actually just read a little more about bolt and see there could be some real advantages in going that route with all the built in syncing features. I did not see any console support though which could be a show stopper for bolt.
     
  4. Defcon44

    Defcon44

    Joined:
    Aug 19, 2013
    Posts:
    400
    Hi,

    i have deleted the slider and make a new one and that works know :s strange ....

    Thanks :p
     
  5. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    10,483
    If you absolutely need split screen, and unless you're willing to heavily modify the RFPS scripts, you should probably use a different asset, or run each player as a separate instance of the game. They can connect to each other over a local network connection (127.0.0.1) instead of actually going over the network.

    What do you mean by "console"? Headless server console? I don't see why you couldn't run one with Bolt.
     
  6. Defcon44

    Defcon44

    Joined:
    Aug 19, 2013
    Posts:
    400
    Hey Tony,

    I have look you'r ammo text video and do you know what i need to change if i want a progress bar for ammo value ?

    Thank you
     
  7. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    10,483
    In AmmoText.cs and WeaponBehavior.cs, where the ammo text steps say to use UnityEngine.UI.Text, use UnityEngine.UI.Slider instead (or in addition). Then set up a Slider where the Text element would be. Finally, in AmmoText.cs use code similar to the healthbar slider steps to set slider.value.
     
    Defcon44 likes this.
  8. Defcon44

    Defcon44

    Joined:
    Aug 19, 2013
    Posts:
    400
    Thank you,

    I have make what you say, no error but when i shoot the bar don't move, and when i reload she move to the up and take a little size :s

    Ammotext.cs:

    Code (CSharp):
    1. //AmmoText.cs by Azuline Studios© All Rights Reserved
    2. using UnityEngine;
    3. using System.Collections;
    4.  
    5. public class AmmoText : MonoBehaviour {
    6.     //draw ammo amount on screen
    7.     public int ammoGui;//bullets remaining in clip
    8.     public int ammoGui2;//total ammo in inventory
    9.     private int oldAmmo = -512;
    10.     private int oldAmmo2 = -512;
    11.     public Color textColor;
    12.     public float horizontalOffset = 0.95f;
    13.     public float verticalOffset = 0.075f;
    14.     [HideInInspector]
    15.     public float horizontalOffsetAmt = 0.78f;
    16.     [HideInInspector]
    17.     public float verticalOffsetAmt = 0.1f;
    18.     public float fontScale = 0.032f;
    19.  
    20.     public UnityEngine.UI.Slider slider;
    21.  
    22.     void OnEnable(){
    23.         var sliderGO = GameObject.Find("Ammo_Bar");
    24.         horizontalOffsetAmt = horizontalOffset;
    25.         verticalOffsetAmt = verticalOffset;  
    26.         GetComponent<GUIText>().fontSize = Mathf.RoundToInt(Screen.height * fontScale);
    27.         oldAmmo = -512;
    28.         oldAmmo2 = -512;
    29.     }
    30.  
    31.     void Update(){
    32.         //only update GUIText if value to be displayed has changed
    33.         if((ammoGui != oldAmmo) || (ammoGui2 != oldAmmo2)) {
    34.             GetComponent<GUIText>().pixelOffset = new Vector2 (Screen.width * horizontalOffsetAmt, Screen.height * verticalOffsetAmt);
    35.          
    36.             GetComponent<GUIText>().text = "Ammo : "+ ammoGui.ToString()+" / "+ ammoGui2.ToString();
    37.          
    38.             GetComponent<GUIText>().material.color = textColor;
    39.             oldAmmo = ammoGui;
    40.             oldAmmo2 = ammoGui2;
    41.  
    42.             if (slider != null) slider.value = Mathf.Clamp(ammoGui2 / 100, 0, 1);
    43.         }
    44.  
    45.     }
    46. }
    Code line in WeaponBehavior.cs :
    Code (CSharp):
    1.         if (AmmoText1 != null) AmmoText1.slider = GetComponentInChildren<UnityEngine.UI.Slider>();
    Do you see the problem ? :s
     
  9. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    10,483
    @Defcon44 - If your ammo bar is not a child of the weapon, remove the lines from WeaponBehavior.cs. In this case, add this line to AmmoText.cs:
    Code (csharp):
    1. void OnEnable(){
    2.     var sliderGO = GameObject.Find("Ammo_Bar");
    3.     slider = sliderGO.GetComponent<UnityEngine.UI.Slider>(); //<-- ADD THIS.
     
  10. Defcon44

    Defcon44

    Joined:
    Aug 19, 2013
    Posts:
    400
    With the new line, the progress bar don't bug (take a little size) but she don't move when i shoot :(

    My progress is a child of the weapon yes.

     
  11. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    10,483
    @Defcon44 - In AmmoText.cs, add this line to the bottom of the Update() method:
    Code (csharp):
    1.     if (slider != null) slider.value = Mathf.Clamp(ammoGui2 / 100, 0, 1);
    2.     if (slider == null) Debug.LogError("Ammo slider is null!"); //<-- ADD THIS.
    3. }
    It won't fix the problem, but it will tell you if the script wasn't able to find the slider.
     
  12. llJIMBOBll

    llJIMBOBll

    Joined:
    Aug 23, 2014
    Posts:
    576
    HI, would anyone know how to invert mouse by script? can this be done with rpfs input manager?

    Thank you
    -Jimbob
     
  13. Defcon44

    Defcon44

    Joined:
    Aug 19, 2013
    Posts:
    400
    Thanks Tony,
    i have place the line and i don't get the error message (Ammo Slider is null!) in the console.
     
  14. Baraff

    Baraff

    Joined:
    Aug 16, 2014
    Posts:
    251
    Using another asset at this stage would not be great as I have already modified a bunch of stuff adding in non AI NPCs for example, I am however going to try and avoid the need for split screen if I can. I just need to convince others. I had not considered a separate instance which could work, but off the top of my head I guess would likely double the load on the machine. I am still trying to avoid having to do it. I have some other ideas that I am going to suggest as alternatives instead.

    Regarding consoles... I am referring to game consoles eg, Xbox One and PlayStation 4. Bolt does not support them and the only reference I could find was hidden deep in a forum post which was a comment that someone was looking at it as a side project. Also, since being acquired by Photon, Bolt source code is no longer available if that would have helped am not sure anyway.

    I did however come across Forge networking in the mean time and it seems like it may also be an option. No concrete evidence that it supports Xbox One or Playstation 4, but they say that if the platform supports C# sockets then it should work. I have not been able to confirm c# sockets support on the consoles yet though.
     
  15. Defcon44

    Defcon44

    Joined:
    Aug 19, 2013
    Posts:
    400
    Ok, so i have check the ammo_bar and when i reload she change the size.

    Before reloading :



    After reloading :



    Any idea about the ammotext script ? :s
     
  16. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    10,483
    In AmmoText.cs, add this line:
    Code (csharp):
    1. public UnityEngine.UI.Slider slider;
    2. public int bulletsPerClip = 1; //<--ADD THIS.
    And change the line in Update() to:
    Code (csharp):
    1. if (uiSlider != null) uiSlider.value = Mathf.Clamp((float) ammoGui / (float) Mathf.Max(1, bulletsPerClip), 0, 1);
    In WeaponBehavior.cs, change this line:
    Code (csharp):
    1. if (AmmoText1 != null) AmmoText1.uiSlider = GetComponentInChildren<UnityEngine.UI.Slider>();
    to this:
    Code (csharp):
    1. if (AmmoText1 != null) {
    2.     AmmoText1.uiSlider = GetComponentInChildren<UnityEngine.UI.Slider>();
    3.     AmmoText1.bulletsPerClip = bulletsPerClip;
    4. }
    in both places (Start and OnEnable).

    Make sure all weapons have a slider on a canvas.

    If it's still not updating, then when you play and switch to the weapon, pause the game. Inspect the AmmoText GameObject. Make sure the UI Slider field is assigned to the weapon's Slider.
     
    Defcon44 likes this.
  17. Defcon44

    Defcon44

    Joined:
    Aug 19, 2013
    Posts:
    400
    Ok thanks, i go test it :)

    Edit:

    That works perfectly ! Thanks Tony for you'r help and for take you'r time for help :)
     
    Last edited: Jan 8, 2016
  18. Defcon44

    Defcon44

    Joined:
    Aug 19, 2013
    Posts:
    400
    i have see a problem with the ammotext script, the script found the Slider but only one slider :

    The progress bar of the weapon X works good but if i take the weapon O that don't works, so i clic on the ammotext prefab and in the Slider slot the Ammo_Bar of the weapon X is here :/
     
  19. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    10,483
    Hmm, I'll take a look later today and let you know what I find.
     
  20. Defcon44

    Defcon44

    Joined:
    Aug 19, 2013
    Posts:
    400
    Ok thanks :)
     
  21. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    10,483
    In WeaponBehavior.cs, move the lines in Start() down after this:
    Code (csharp):
    1. void Start () {
    2.     //... lines of code ...
    3.  
    4.     //Access GUIText instance that was created by the PlayerWeapons script
    5.     ammoGuiObj = PlayerWeaponsComponent.ammoGuiObjInstance;
    6.     AmmoText1 = ammoGuiObj.GetComponent<AmmoText>();//set reference for main color element of ammo GUIText
    7.     AmmoText2 = ammoGuiObj.GetComponentsInChildren<AmmoText>();//set reference for shadow background color element of heath GUIText
    8.  
    9.     // MOVE THE LINES TO HERE:
    10.     if (AmmoText1 != null) {
    11.         AmmoText1.uiSlider = GetComponentInChildren<UnityEngine.UI.Slider>();
    12.         AmmoText1.bulletsPerClip = bulletsPerClip;
    13.     }
    14.  
    15.     //Initialize audio sources
    16.     aSources = weaponObj.GetComponents<AudioSource>();
    17.     //... lines of code ...
    18. }
    I had given you the instructions for RFPS 1.21. This changed in RFPS 1.22.
     
    Defcon44 likes this.
  22. Defcon44

    Defcon44

    Joined:
    Aug 19, 2013
    Posts:
    400
    Hum .... I have all ready this lines here in my script :S

    And i have the same lines on the 343 lines (like the tuto of ammo text) but the problem still here :(

    Edit: My bad, the second lines in 343 is not in the Void Update section --'

    I have moved the lines code to the 365 line and that works now ! :D

    Thank you Tony
     
  23. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    10,483
    I'm glad it's working now! Do you have any screenshots of your game?
     
    Defcon44 likes this.
  24. Defcon44

    Defcon44

    Joined:
    Aug 19, 2013
    Posts:
    400
    Yeah !
    For now i work on The Last Hope For All but i have begin a little project called "The Divine Doors" i can't tell you what is it because i work on the base but this is a second little project ;)

    I would make a big post when i launch the game :)
     
    Deleted User and TonyLi like this.
  25. Deleted User

    Deleted User

    Guest

    Thanks again for the playtesting, Takahama. The NPCs were being tested with different update intervals, they should respond faster in the new demo. This can be customized by decreasing the "yield return new WaitForSeconds(0.5f);" lines to something like 0.3f at the end of the AI methods in AI.cs. As for crouched and prone movement up slopes, this has also been fixed. You can change this yourself if you need to in FPSRigidBodyWalker.cs by adding this condition check around the additional gravity code:

    Code (CSharp):
    1.                     //apply gravity
    2.                     if((!prone && !crouched) || !grounded){//only apply additional gravity when not prone/crouched to allow player to move up steep slopes
    3.                         RigidbodyComponent.AddForce(new Vector3 (0f, Physics.gravity.y * RigidbodyComponent.mass, 0f));
    4.                     }

    @Gua, We've made a script called MovePlayerAndCamera.cs for the next version which can be used for cutscenes. It can release control of the main camera and then another script or plugin could animate it with a spline curve through the level while positioning animated hands in view. I'll post it here if you think you could use it for your project:

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class MovePlayerAndCamera : MonoBehaviour {
    5.  
    6.     public float moveCamPitch;//angles that player will be looking after move
    7.     public float moveCamYaw;
    8.     public AI testAI;
    9.     public Transform testPos;//position to move player to
    10.     private bool toggleState;
    11.     private bool toggleGuiState;
    12.     private bool noCrosshair;
    13.     public GameObject FPSWeaponsObj;
    14.     public GameObject FPSPlayerObj;
    15.     public GameObject FPSCameraObj;
    16.     public GameObject MainCameraObj;
    17.     public GameObject CinemaCameraObj;//a camera object whose angles and postion will be default after toggling camera control
    18.     public GameObject VisibleBodyObj;
    19.     private AudioListener ListenerComponent;
    20.     private CameraKick CameraKickComponent;
    21.     private SmoothMouseLook MouseLookComponent;
    22.     private InputControl InputComponent;
    23.     private FPSPlayer FPSPlayerComponent;
    24.     private FPSRigidBodyWalker FPSWalkerComponent;
    25.     private PlayerWeapons PlayerWeaponsComponent;
    26.     private Ironsights IronsightsComponent;
    27.     private GunSway GunSwayComponent;
    28.     private HorizontalBob HBobComponent;
    29.     private VerticalBob VBobComponent;
    30.  
    31.     void Start () {
    32.         //set up component references
    33.         CinemaCameraObj.SetActive(false);
    34.         CameraKickComponent = MainCameraObj.GetComponent<CameraKick>();
    35.         MouseLookComponent = FPSCameraObj.GetComponent<SmoothMouseLook>();
    36.         InputComponent = FPSPlayerObj.GetComponent<InputControl>();
    37.         FPSPlayerComponent = FPSPlayerObj.GetComponent<FPSPlayer>();
    38.         FPSWalkerComponent = FPSPlayerObj.GetComponent<FPSRigidBodyWalker>();
    39.         ListenerComponent = MainCameraObj.GetComponent<AudioListener>();
    40.         PlayerWeaponsComponent = FPSWeaponsObj.GetComponent<PlayerWeapons>();
    41.         IronsightsComponent = FPSPlayerObj.GetComponent<Ironsights>();
    42.         GunSwayComponent = FPSWeaponsObj.GetComponent<GunSway>();
    43.         HBobComponent = FPSPlayerObj.GetComponent<HorizontalBob>();
    44.         VBobComponent = FPSPlayerObj.GetComponent<VerticalBob>();
    45.         if(!FPSPlayerComponent.crosshairEnabled){
    46.             noCrosshair = true;//don't reactivate crosshair if it wasn't active to start
    47.         }
    48.     }
    49.    
    50.     //Detect keypresses for camera and player positioning tests (testing)
    51.     void Update () {
    52.         if(Time.timeSinceLevelLoad > 0.2f){
    53. //            if(Input.GetKeyDown(KeyCode.Comma)){
    54. //                testAI.GoToPosition(testPos.position);//move npc to a particular place
    55. //            }
    56.             if(Input.GetKeyDown(KeyCode.Backspace)){
    57.                 MovePlayer(testPos.position, moveCamYaw, moveCamPitch);//move player with camera
    58.             }
    59.             if(Input.GetKeyDown(KeyCode.Delete)){
    60.                 ReleaseMainCamera();//release main camera from RFPSP control, for cinematics or other purposes
    61.             }
    62.             if(Input.GetKeyDown(KeyCode.End)){
    63.                 ReleaseMainCameraAndMovePlayer();//release main camera from RFPSP control, for cinematics or other purposes, then reposition player and set camera angles afterwards
    64.             }
    65.         }
    66.     }
    67.    
    68.     //move player with camera
    69.     public void MovePlayer (Vector3 position, float camYaw = 0f, float camPitch = 0f){
    70.    
    71.         if(!FPSPlayerObj.activeInHierarchy){
    72.             return;//don't move player if it isn't active
    73.         }
    74.    
    75.         CancelPlayerActions();
    76.    
    77.         //set the time that the player moved in these scripts, to reduce lerp/smoothing times for instant transition
    78.         CameraKickComponent.movingTime = Time.time;
    79.         MouseLookComponent.playerMovedTime = Time.time;
    80.        
    81.         //move camera to position, and add player height
    82.         Vector3 tempCamPosition = position + (Vector3.up * FPSWalkerComponent.standingCamHeight);
    83.        
    84.         //change camera position
    85.         CameraKickComponent.tempLerpPos = tempCamPosition;
    86.         CameraKickComponent.tempPosition = tempCamPosition;
    87.         CameraKickComponent.targetPos = tempCamPosition;
    88.        
    89.         //change player object positions
    90.         FPSPlayerObj.transform.position = position;
    91.         FPSCameraObj.transform.position = tempCamPosition;
    92.         FPSWeaponsObj.transform.position = FPSCameraObj.transform.position;
    93.         VisibleBodyObj.transform.position = position;
    94.        
    95.         //set camera angles to those defined by the MovePlayer "camYaw" and "camPitch" arguments
    96.         //so player can be looking in a certain direction after moving
    97.         if(camYaw != 0f){//don't modify camera angles if MovePlayer was called with none specified
    98.             //Set view angles to those defined by camYaw and camPitch parameters
    99.             FPSCameraObj.transform.rotation = Quaternion.Euler(-camPitch, camYaw, 0f);
    100.             FPSWeaponsObj.transform.rotation = FPSCameraObj.transform.rotation;
    101.             MouseLookComponent.rotationX = camYaw;
    102.             MouseLookComponent.rotationY = camPitch;
    103.             //Reset angle amounts below to zero, to allow view movement to resume at new angles
    104.             MouseLookComponent.horizontalDelta = 0f;
    105.             MouseLookComponent.recoilY = 0f;
    106.             MouseLookComponent.recoilX = 0f;
    107.             MouseLookComponent.xQuaternion = Quaternion.Euler(0f, 0f, 0f);
    108.             MouseLookComponent.yQuaternion = Quaternion.Euler(0f, 0f, 0f);
    109.             MouseLookComponent.originalRotation = Quaternion.Euler(0f, 0f, 0f);
    110.         }
    111.     }
    112.    
    113.     public void ToggleGuiDisplay(){
    114.         if(!toggleGuiState){
    115.             if(!noCrosshair){FPSPlayerComponent.CrosshairGuiTexture.enabled = false;}
    116.             FPSPlayerComponent.healthGuiObjInstance.SetActive(false);
    117.             FPSPlayerComponent.thirstGuiObjInstance.SetActive(false);
    118.             FPSPlayerComponent.hungerGuiObjInstance.SetActive(false);
    119.             FPSPlayerComponent.helpGuiObjInstance.SetActive(false);
    120.             PlayerWeaponsComponent.ammoGuiObjInstance.SetActive(false);
    121.            
    122.             toggleGuiState = true;
    123.  
    124.         }else{
    125.            
    126.             if(!noCrosshair){FPSPlayerComponent.CrosshairGuiTexture.enabled = true;}//don't toggle crosshair if it wasn't active to start
    127.             FPSPlayerComponent.healthGuiObjInstance.SetActive(true);
    128.             FPSPlayerComponent.thirstGuiObjInstance.SetActive(true);
    129.             FPSPlayerComponent.hungerGuiObjInstance.SetActive(true);
    130.             FPSPlayerComponent.helpGuiObjInstance.SetActive(true);
    131.             PlayerWeaponsComponent.ammoGuiObjInstance.SetActive(true);
    132.            
    133.             toggleGuiState = false;
    134.         }
    135.     }
    136.    
    137.     //toggle a camera other than the main camera
    138.     public void ToggleCinemaCamera(){
    139.         if(!toggleState){
    140.        
    141.             ToggleGuiDisplay();
    142.            
    143.             FPSWeaponsObj.SetActive(false);
    144.             FPSPlayerObj.SetActive(false);
    145.             FPSCameraObj.SetActive(false);
    146.             VisibleBodyObj.SetActive(false);
    147.            
    148.             CinemaCameraObj.SetActive(true);
    149.  
    150.             toggleState = true;
    151.  
    152.         }else{
    153.  
    154.             CinemaCameraObj.SetActive(false);
    155.            
    156.             CameraKickComponent.movingTime = Time.time;
    157.             MouseLookComponent.playerMovedTime = Time.time;
    158.        
    159.             FPSCameraObj.SetActive(true);
    160.             FPSWeaponsObj.SetActive(true);
    161.             FPSPlayerObj.SetActive(true);
    162.             VisibleBodyObj.SetActive(true);
    163.            
    164.             CancelPlayerActions();
    165.             ToggleGuiDisplay();
    166.  
    167.             toggleState = false;
    168.         }
    169.     }
    170.    
    171.     //release control of the main camera for other uses like cinema scenes
    172.     public void ReleaseMainCamera(){
    173.         if(!toggleState){
    174.        
    175.             ToggleGuiDisplay();
    176.             FPSWeaponsObj.SetActive(false);
    177.             FPSPlayerObj.SetActive(false);
    178.             VisibleBodyObj.SetActive(false);
    179.            
    180.             CameraKickComponent.enabled = false;
    181.             MouseLookComponent.enabled = false;
    182.             MainCameraObj.transform.position = CinemaCameraObj.transform.position;
    183.             MainCameraObj.transform.rotation = CinemaCameraObj.transform.rotation;
    184.            
    185.             Camera.main.fieldOfView = IronsightsComponent.defaultFov;
    186.            
    187.             toggleState = true;
    188.  
    189.         }else{
    190.            
    191.             MainCameraObj.transform.rotation = FPSCameraObj.transform.rotation;
    192.             MainCameraObj.transform.position = FPSCameraObj.transform.position;
    193.             CameraKickComponent.enabled = true;
    194.             MouseLookComponent.enabled = true;
    195.            
    196.             FPSWeaponsObj.SetActive(true);
    197.             FPSPlayerObj.SetActive(true);
    198.             VisibleBodyObj.SetActive(true);
    199.            
    200.             CancelPlayerActions();
    201.             ToggleGuiDisplay();
    202.            
    203.             toggleState = false;
    204.         }
    205.     }
    206.    
    207.     //release main camera from RFPSP control, for cinematics or other purposes, then reposition player and set camera angles when reactivating camera
    208.     public void ReleaseMainCameraAndMovePlayer(){
    209.         if(!toggleState){
    210.            
    211.             ToggleGuiDisplay();
    212.             FPSWeaponsObj.SetActive(false);
    213.             FPSPlayerObj.SetActive(false);
    214.             VisibleBodyObj.SetActive(false);
    215.            
    216.             CameraKickComponent.enabled = false;
    217.             MouseLookComponent.enabled = false;
    218.             MainCameraObj.transform.position = CinemaCameraObj.transform.position;
    219.             MainCameraObj.transform.rotation = CinemaCameraObj.transform.rotation;
    220.            
    221.             Camera.main.fieldOfView = IronsightsComponent.defaultFov;
    222.            
    223.             toggleState = true;
    224.  
    225.         }else{
    226.            
    227.             MainCameraObj.transform.rotation = FPSCameraObj.transform.rotation;
    228.             MainCameraObj.transform.position = FPSCameraObj.transform.position;
    229.             CameraKickComponent.enabled = true;
    230.             MouseLookComponent.enabled = true;
    231.            
    232.             FPSWeaponsObj.SetActive(true);
    233.             FPSPlayerObj.SetActive(true);
    234.            
    235.             VisibleBodyObj.SetActive(true);
    236.            
    237.             CancelPlayerActions();
    238.             ToggleGuiDisplay();
    239.             MovePlayer(testPos.position, moveCamYaw, moveCamPitch);
    240.            
    241.             toggleState = false;
    242.         }
    243.     }
    244.    
    245.     //cancel actions like jumping, crouching, sprinting, reloading, and weapon switching
    246.     //so player resumes after camera switch in a neutral state
    247.     void CancelPlayerActions(){
    248.    
    249.         WeaponBehavior CurrentWeaponBehaviorComponent = PlayerWeaponsComponent.CurrentWeaponBehaviorComponent;
    250.    
    251.         PlayerWeaponsComponent.StopAllCoroutines();
    252.         CurrentWeaponBehaviorComponent.StopAllCoroutines();
    253.        
    254.         FPSWalkerComponent.jumping = false;
    255.         FPSWalkerComponent.landState = false;
    256.         FPSWalkerComponent.jumpfxstate = true;
    257.         FPSWalkerComponent.CameraAnimationComponent.Rewind("CameraLand");
    258.        
    259.         FPSWalkerComponent.crouched = false;
    260.         FPSWalkerComponent.crouchState = false;
    261.         FPSWalkerComponent.crouchRisen = true;
    262.        
    263.         FPSWalkerComponent.prone = false;
    264.         FPSWalkerComponent.proneState = false;
    265.         FPSWalkerComponent.proneRisen = true;
    266.        
    267.         if(CurrentWeaponBehaviorComponent && !CurrentWeaponBehaviorComponent.PistolSprintAnim){
    268.             CurrentWeaponBehaviorComponent.AnimationComponent.Rewind("RifleSprinting");
    269.             CurrentWeaponBehaviorComponent.AnimationComponent["RifleSprinting"].normalizedTime = 0;
    270.         }else{
    271.             CurrentWeaponBehaviorComponent.AnimationComponent.Rewind("PistolSprinting");
    272.             CurrentWeaponBehaviorComponent.AnimationComponent["PistolSprinting"].normalizedTime = 0;
    273.         }
    274.        
    275.         CurrentWeaponBehaviorComponent.gunAnglesTarget = Vector3.zero;
    276.        
    277.         IronsightsComponent.switchMove = 0.0f;
    278.         IronsightsComponent.reloading = false;
    279.        
    280.         FPSPlayerComponent.zoomed = false;
    281.         IronsightsComponent.newFov = IronsightsComponent.defaultFov;
    282.         IronsightsComponent.nextFov = IronsightsComponent.defaultFov;
    283.        
    284.         FPSWalkerComponent.cancelSprint = true;
    285.         FPSWalkerComponent.sprintActive = false;
    286.         FPSWalkerComponent.jumping = false;
    287.         FPSWalkerComponent.landState = false;
    288.         FPSWalkerComponent.jumpfxstate = true;
    289.         FPSWalkerComponent.CameraAnimationComponent.Rewind("CameraLand");
    290.        
    291.         if(CurrentWeaponBehaviorComponent.WeaponAnimationComponent){
    292.             CurrentWeaponBehaviorComponent.WeaponAnimationComponent.Stop();
    293.             CurrentWeaponBehaviorComponent.WeaponAnimationComponent.CrossFade("Fire",0.01f,PlayMode.StopSameLayer);
    294.             CurrentWeaponBehaviorComponent.WeaponAnimationComponent["Fire"].normalizedTime = 1f;
    295.         }
    296.    
    297.     }
    298.    
    299. }
    The CameraKickComponent.movingTime var is used in CameraKick.cs to "snap" the camera instantly after repositioning and needs to be added to this section:

    Code (CSharp):
    1.             //lerp camera normally if not on elevator or moving platform
    2.             if(movingTime + 0.75f > Time.time){
    3.                 lerpSpeedAmt = 0f;
    4.             }else{
    5.                 if((FPSPlayerComponent.removePrefabRoot && playerObj.transform.parent == null)
    6.                 ||(!FPSPlayerComponent.removePrefabRoot && playerObj.transform.parent == FPSWalkerComponent.mainObj.transform)){
    7.                     lerpSpeedAmt = Mathf.MoveTowards(lerpSpeedAmt, camSmoothSpeed, Time.deltaTime);//gradually change lerpSpeedAmt for smoother lerp transition
    8.                 }else{//faster camera lerp speed on platforms or elevators to minimize camera position lag
    9.                     lerpSpeedAmt = Mathf.MoveTowards(lerpSpeedAmt, 0.015f, Time.deltaTime);
    10.                 }
    11.             }
    And near the end of CameraKick.cs to stop the jumping camera movement after releasing the main camera or moving the player:

    Code (CSharp):
    1.             if(movingTime + 0.75f < Time.time){
    2.                 IronsightsComponent.jumpAmt = gunDown;
    3.             }else{
    4.                 IronsightsComponent.jumpAmt = 0f;
    5.             }
    The MouseLookComponent.playerMovedTime var can be added to SmoothMouseLook.cs to snap the camera angles as well:

    Code (CSharp):
    1.             if(playerMovedTime + 0.5f < Time.time){
    2.                 //smooth the mouse input
    3.                 myTransform.rotation = Quaternion.Slerp(myTransform.rotation , originalRotation * xQuaternion * yQuaternion, smoothSpeed * Time.smoothDeltaTime * 60 / Time.timeScale);
    4.             }else{
    5.                 myTransform.rotation = originalRotation * xQuaternion * yQuaternion;//snap camera instantly to angles with no smoothing
    6.             }
    As for the script itself, the MovePlayer() method can instantly teleport the player to a position and make them look in the direction defined by the moveCamYaw and moveCamPitch vars in the inspector after the move. ReleaseMainCameraAndMovePlayer() does the same thing, except when first called, it releases the main camera from RFPSP control and moves it to the position and angles of the cinemaCameraObj, where it can be scripted for cinematics. Afterwards, the player is moved to the testPos position and camera control is resumed by the RFPSP. ToggleCinemaCamera() will toggle the display of a separate camera with different image effects/settings, and ReleaseMainCamera() will toggle on/off control of the main camera without moving the player. If you have any questions about this script. Please let us know.


    Hi DownFall, this is related to a computer graphics issue called z-fighting. It is more noticeable when using the 1 camera setup at player distances greater than around 1000 or -1000 units from the scene origin (coords 0,0,0,). The 1 camera prefab uses a closer near clip plane, which reduces accuracy for the zbuffer at farther distances and for objects that are close to overlapping. The 1 camera prefab is good for small scenes where you want to cast scene shadows on the player's weapons.

    The 2 camera setup is better suited for scenes as large as 36km^2 at distances of 3000 and -3000 units from the origin. The 2 camera setup uses scaled up weapons and a farther near clip plane value, which significantly reduces z-fighting in large scenes. Hope that helps.


    Hi TA_Ahmad, it looks like your script is modifying WeaponBehavior.zoomFOV directly. Is the problem that the zoom amount is not resetting to the original value? You might want to try storing the original ZoomFov value in a separate variable like ZoomFovOrig in the Start() method and recalling it when unzoomed. Your script looks like it should work, but I'll see if I can find any other issues with it.


    Sure llJIMBOBll, you can add a bool called invertVerticalLook in SmoothMouseLook.cs and add this condition check:

    Code (CSharp):
    1.                 if(!invertVerticalLook){
    2.                     rotationY += InputComponent.lookY * sensitivityAmt * Time.timeScale;
    3.                 }else{
    4.                     rotationY -= InputComponent.lookY * sensitivityAmt * Time.timeScale;
    5.                 }

    Development on the next version is going well, but there is one last-minute feature being implemented that might delay our mid-January estimate. The addition of per limb/bone hit detection for NPCs will allow location based hit detection and damage amounts, better ragdoll transitions (ragdoll-at-will :D), and possible pooling of NPC prefabs. Our new estimate is a release sometime this month. Appologies for the delay, but this feature is needed to implement bow and arrow weapons up to our standards, as well as improving the overall workings of the NPCs.

    There is also an updated webplayer preview demo to try out. Since our last post, friendly NPCs have been added who follow and assist the player. When pressing the use button on a friendly NPC, they will toggle between follow and hold postition behaviors. If the NPC(s) are following you, you can press the use key, and the following NPCs will travel to the point on the map under the crosshair. The NPC's in the demo are just an example and any combination of character models and vocal sound effects can be used. There is also an option to prevent the NPCs from following with the use key, so the folllowing and go-to-position AI behaviors can be activated by a quest script, trigger, or other game event.

    Another new feature is camera switching and player scripted moving/teleporting. The delete key toggles the camera, the end key toggles the camera and repositions the player afterwards, and backspace moves the player to a predefined position.

    As a review of the other features in the development demo: the middle mouse button throws grenades, the v key performs a melee hit with the MP5 (other weapons to follow), zooming with melee weapons block melee attacks, and backstabs can be performed with a melee weapon if an enemy NPC is unaware of the player.

    Issues present in the demo which have been fixed are: shotgun hand model snaps to reload animation after throwing grenade, and crouching and prone movement don't move up steep slopes.

    The remaining tasks for the next version are melee animations for the ranged weapons, bow and arrow, and improved hit detection using colliders per body part. Thanks for your patience.
     
    Gua, Defcon44, SteveRyu and 4 others like this.
  26. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    10,483
    @Azuline Studios - Not to delay the release any further, but may I request Unity UI support? Please feel free to take ideas from the ammo text and health text changes I posted previously. A lot of RFPS users have wanted to put ammo readouts on their weapons using a Unity UI world space canvas, and to support sliders for numeric values such as health bars, ammo bars, etc. It would be great to have this built in, rather than modifying the RFPS code to support it.
     
  27. Takahama

    Takahama

    Joined:
    Feb 18, 2014
    Posts:
    166
    @Azuline Studios 10/10!
    YAY!!! Time for reports!
    1. if you press F rapidly to friendly soldiers, they gonna say stuff like crazy :D Any cooldown or a timer for each command is possible ?

    2. How it happened i dont know but trigger hand and weapon itself is changed position after using grenade (M4 weapon)

    2.5. Oh and what about sneaking/hiding in bushes ? :D
     
    llJIMBOBll likes this.
  28. llJIMBOBll

    llJIMBOBll

    Joined:
    Aug 23, 2014
    Posts:
    576
    @Azuline Studios 10552124554678654321354645645/10!
    Thank youuuu soooo muchhh!! xD

    Can't wait for the update!
    and agree with TonyLi about adding Unity UI as default, would save some time. TonyLi's instructions are very good and I wouldn't of had UI without him :D
     
    Deleted User likes this.
  29. Hormic

    Hormic

    Joined:
    Aug 12, 2014
    Posts:
    251
  30. NinjaMaster

    NinjaMaster

    Joined:
    May 16, 2015
    Posts:
    7
    How do you get the NPC spawners to work? I put one in my scene but nothing spawns.
     
  31. NinjaMaster

    NinjaMaster

    Joined:
    May 16, 2015
    Posts:
    7
    Never mind, I got it working...... stupid me :)
     
  32. Defcon44

    Defcon44

    Joined:
    Aug 19, 2013
    Posts:
    400
    @Azuline Studios Thanks Azuline for this :) just can say : That update dude oO !!!!!!
    Can't wait for this :D

    @TonyLi Yeah great idea Tony! Do not forget to say how long we(you ^^) spent has to solve concerns of progress bar xD
     
    Deleted User likes this.
  33. Ludo97

    Ludo97

    Joined:
    Dec 9, 2015
    Posts:
    121
    Hello I have several problems with " Main 1 FPS Camera " . When I hit the ground flashes , the landscape far " blurs " , and when I go under water texture flashes. While the "FPS 2 Main Camera " no problem , can you help me? more details see potos .
     

    Attached Files:

  34. NeuroToxin-Studios

    NeuroToxin-Studios

    Joined:
    Dec 7, 2014
    Posts:
    68
    This is a known issue and is caused by Z-fighting, this normally occurs with the Main 1 FPS Camera due to its near clipping plane, if using the 1 Camera set up is essential you will need to make the scene as close to 0, 0, 0 as possible as this will reduce the issue.
     
  35. Ludo97

    Ludo97

    Joined:
    Dec 9, 2015
    Posts:
    121
    Thank you for the reply, although I would use FPS 2 Main Camera but there is a bug in the water and the screen turns white.
     
  36. NeuroToxin-Studios

    NeuroToxin-Studios

    Joined:
    Dec 7, 2014
    Posts:
    68
    By a bug in the water do you mean the water goes nuts and "floats" in the air? if so then this is an issue I have also had but have not found a fix yet
     
  37. Ludo97

    Ludo97

    Joined:
    Dec 9, 2015
    Posts:
    121
    Exactly but except me when I go under water completemp the image is white and when I leave the water the image returns to normal
     
  38. Ludo97

    Ludo97

    Joined:
    Dec 9, 2015
    Posts:
    121
    A picture before I get in the water and an image after I go into the water and it is the white bug
     

    Attached Files:

  39. Deleted User

    Deleted User

    Guest

    Sure, will look into this. The GUITexts were meant as a very basic stand-in feature, but an updated GUI would be convenient. We'd probably move all the GUI code to a single script too, like we did for the input calls in InputControl.cs. Thanks for the suggestion!


    Good ideas, Takahama. The soldiers could probably use a cool-down timer for commands. Will do some testing with the weapon model positions changing after using a grenade. Maybe it happens after a CPU spike. The hiding feature would be neat too, and have multiple uses, like a dark area or safe zones.


    Yes, VR support will be added, but probably in a future version, once the main gameplay features have been implemented (many of those will be in the next update).


    Hi ludo97, the first thing you can try is checking if the Weapon Camera, which is a child of the Main Camera object, has its rendering path set to "forward" and not "deferred." The white screen happens due to using the advanced water shader and 2 cameras.

    Also, if you find that your scenes are glowing too much, it might be that the Sun Shafts image effect does not have a directional light assigned, and is casting rays from the whole sky, instead of just a sun/moon light. You can add this code to SunShafts.cs to automatically assign a directional light in your scene:

    Code (CSharp):
    1.         void Start (){
    2.             //automatically assign sunlight
    3.             if(!sunTransform){
    4.                 Light[] lightList = FindObjectsOfType(typeof(Light)) as Light[];
    5.                 for(int i = 0; i < lightList.Length; i++)    {
    6.                     if(lightList[i].type == LightType.Directional && lightList[i].gameObject.activeInHierarchy){
    7.                         sunTransform = lightList[i].transform;
    8.                         break;
    9.                     }
    10.                 }
    11.             }
    12.         }
    We'll look into the floating water issue. You can try reimporting the newest version of the shader from Unity's standard assets, using the default directory structure for the shaders, then adding it to the Water Zone prefab. Hope that helps.
     
    Hormic and Defcon44 like this.
  40. Ludo97

    Ludo97

    Joined:
    Dec 9, 2015
    Posts:
    121
    "has its rendering path set to "forward" and not "deferred."

    This is where the option on the camera ? I look everywhere on both cameras but I did not find and thank you for the script.
     
  41. NinjaMaster

    NinjaMaster

    Joined:
    May 16, 2015
    Posts:
    7
    Does anyone else have a problem with the soldier NPCs shooting through walls? I can't seem to fix it.
     
  42. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    10,483
    Is the Layer correct for your walls?
     
  43. SteveRyu

    SteveRyu

    Joined:
    Apr 9, 2014
    Posts:
    121
    Set to World Collision
     
  44. Stanchion

    Stanchion

    Joined:
    Sep 30, 2014
    Posts:
    268
    Bolt will have official integration for XB1 and PS4 soon
     
  45. Baraff

    Baraff

    Joined:
    Aug 16, 2014
    Posts:
    251
    Have they now said that it is coming soon? If so, then it may be an option.

    Still some things to consider, like which one provides the most useful features.. eg matchmaking/lobby. I thought with bolt you may need to create all of this but perhaps Forge they already have it? Still need to check to see.
     
  46. Stanchion

    Stanchion

    Joined:
    Sep 30, 2014
    Posts:
    268
    I'm saying it right now :) The Steam integration coming out very soon has all those features. They are also planned for the console integrations.
     
  47. Baraff

    Baraff

    Joined:
    Aug 16, 2014
    Posts:
    251
    OK. Thanks for the info. Steam integration is useful and definitely consoles with full features. Definitely worth a look into it.
     
  48. Defcon44

    Defcon44

    Joined:
    Aug 19, 2013
    Posts:
    400
    Hey guy's !
    What's up ?

    I have a question about rfps, how i can make something like this :



    I thing i need a second camera like "scope camera" but how i can show the "camera view" in the scope ? :/

    Thank you
     
  49. SteveRyu

    SteveRyu

    Joined:
    Apr 9, 2014
    Posts:
    121
    Use RenderTexture
     
    Defcon44 likes this.
  50. Defcon44

    Defcon44

    Joined:
    Aug 19, 2013
    Posts:
    400
    I go test is :)

    Thanks Reality!
     
    SteveRyu likes this.
unityunity