Search Unity

  1. All Pro and Enterprise subscribers: find helpful & inspiring creative, tech, and business know-how in the new Unity Success Hub. Sign in to stay up to date.
    Dismiss Notice
  2. Dismiss Notice

Realistic FPS Prefab [RELEASED]

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

  1. llJIMBOBll

    llJIMBOBll

    Joined:
    Aug 23, 2014
    Posts:
    578
    It looks good! One thing I will ask is if you can make it so we can adjust the time it takes to ads, like most modern shooters ads is almost instant. Thanks
     
  2. ProBrStalker

    ProBrStalker

    Joined:
    Aug 20, 2017
    Posts:
    21
    Good night guys, I'm trying to integrate the RFPS with the Mirror Network, but I end up getting several reference errors (26 in total),
    after instantiating the player in the scene, I don't know if it is due to a wrong conversion in the script,
    maybe getting the script the wrong way ... honestly I don't know ...
    Any ideas on what to do or rewrite?

    This is the script:
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using Mirror;
    5.  
    6. public class Player : NetworkBehaviour
    7. {
    8.     public Camera _MainCamera;
    9.     public Camera _WeaponCamera;
    10.     public FPSPlayer _FPSPlayerComponent;
    11.     public FPSRigidBodyWalker _FPSWalker;
    12.     public Ironsights _Ironsights;
    13.     public InputControl _InputControl;
    14.     public DragRigidbody _DragRigibody;
    15.     public PlayerWeapons _PlayerWeapons;
    16.     public GunSway _GunSway;
    17.     public WeaponEffects _WeaponEffects;
    18.     public CamAndWeapAnims _CamAndWeapAnims;
    19.     public ReconfigurePrefab _ReconfigurePrefab;
    20.     public SmoothMouseLook _SmoothMouseLook;
    21.     public Footsteps _Foootsteps;
    22.     public MovePlayerAndCamera _MovePlayerAndCamera;
    23.     public PlayerCharacter _PlayerCharacter;
    24.     public CameraControl _CameraControl;
    25.     // Start is called before the first frame update
    26.  
    27.     void OnValidate()
    28.     {
    29.         //!!!FPSCamera
    30.         if (_CamAndWeapAnims == null)
    31.             _CamAndWeapAnims = GetComponentInChildren<CamAndWeapAnims>();
    32.          
    33.         if (_ReconfigurePrefab == null)
    34.             _ReconfigurePrefab = GetComponentInChildren<ReconfigurePrefab>();
    35.          
    36.         if (_SmoothMouseLook == null)
    37.             _SmoothMouseLook = GetComponentInChildren<SmoothMouseLook>();
    38.          
    39.         if (_Foootsteps == null)
    40.             _Foootsteps = GetComponentInChildren<Footsteps>();
    41.          
    42.         if (_CameraControl == null)
    43.             _CameraControl = GetComponentInChildren<CameraControl>();
    44.      
    45.         //!!!FPSPlayer
    46.      
    47.         if (_FPSPlayerComponent == null)
    48.             _FPSPlayerComponent = GetComponentInChildren<FPSPlayer>();
    49.          
    50.         if (_FPSWalker == null)
    51.             _FPSWalker = GetComponentInChildren<FPSRigidBodyWalker>();
    52.          
    53.         if (_Ironsights == null)
    54.             _Ironsights = GetComponentInChildren<Ironsights>();
    55.          
    56.         if (_InputControl == null)
    57.             _InputControl = GetComponentInChildren<InputControl>();
    58.          
    59.         if (_DragRigibody == null)
    60.             _DragRigibody = GetComponentInChildren<DragRigidbody>();
    61.          
    62.         //!!!FPSWeapons
    63.          
    64.         if (_PlayerWeapons == null)
    65.             _PlayerWeapons = GetComponentInChildren<PlayerWeapons>();
    66.          
    67.         if (_GunSway == null)
    68.             _GunSway = GetComponentInChildren<GunSway>();
    69.          
    70.         if (_WeaponEffects == null)
    71.             _WeaponEffects = GetComponentInChildren<WeaponEffects>();
    72.          
    73.         //!!!VisibleBody
    74.      
    75.         if (_PlayerCharacter == null)
    76.             _PlayerCharacter = GetComponentInChildren<PlayerCharacter>();
    77.          
    78.     }
    79.  
    80.     void Start()
    81.     {
    82.              
    83.     }
    84.  
    85.     public override void OnStartLocalPlayer()
    86.     {
    87.         _MainCamera.enabled = hasAuthority;
    88.         _WeaponCamera.enabled = hasAuthority;
    89.         {
    90.             Transform MaincameraTransform = _MainCamera.transform;
    91.             MaincameraTransform.parent = _MainCamera.transform;
    92.             MaincameraTransform.position = _MainCamera.transform.position;
    93.             MaincameraTransform.rotation = _MainCamera.transform.rotation;
    94.          
    95.             Transform WeaponCameraTransform = _WeaponCamera.transform;
    96.             WeaponCameraTransform.parent = _WeaponCamera.transform;
    97.             WeaponCameraTransform.position = _WeaponCamera.transform.position;
    98.             WeaponCameraTransform.rotation = _WeaponCamera.transform.rotation;
    99.          
    100.             //!!!FPSCamera
    101.             _CamAndWeapAnims.enabled = hasAuthority;
    102.             _CamAndWeapAnims.GetComponentInChildren<CamAndWeapAnims>();
    103.      
    104.             _ReconfigurePrefab.enabled = hasAuthority;
    105.             _ReconfigurePrefab.GetComponentInChildren<ReconfigurePrefab>();
    106.      
    107.             _SmoothMouseLook.enabled = hasAuthority;
    108.             _SmoothMouseLook.GetComponentInChildren<SmoothMouseLook>();
    109.      
    110.             _CameraControl.enabled = hasAuthority;
    111.             _CameraControl.GetComponentInChildren<CameraControl>();
    112.  
    113.             //!!!FPSPlayer
    114.      
    115.             _FPSWalker.enabled = isLocalPlayer;
    116.             _FPSWalker.GetComponentInChildren<FPSRigidBodyWalker>();
    117.      
    118.             _FPSPlayerComponent.enabled = hasAuthority;
    119.             _FPSPlayerComponent.GetComponentInChildren<FPSPlayer>();
    120.      
    121.             _Ironsights.enabled = hasAuthority;
    122.             _Ironsights.GetComponentInChildren<Ironsights>();
    123.      
    124.             _InputControl.enabled = hasAuthority;
    125.             _InputControl.GetComponentInChildren<InputControl>();
    126.      
    127.             _DragRigibody.enabled = hasAuthority;
    128.             _DragRigibody.GetComponentInChildren<DragRigidbody>();
    129.      
    130.             //!!!FPSWeapons
    131.      
    132.             _PlayerWeapons.enabled = hasAuthority;
    133.             _PlayerWeapons.GetComponentInChildren<PlayerWeapons>();
    134.      
    135.             _GunSway.enabled = hasAuthority;
    136.             _GunSway.GetComponentInChildren<PlayerWeapons>();
    137.      
    138.             _WeaponEffects.enabled = hasAuthority;
    139.             _WeaponEffects.GetComponentInChildren<WeaponEffects>();
    140.      
    141.             ///VisibleBody
    142.             _PlayerCharacter.enabled = hasAuthority;
    143.             _PlayerCharacter.GetComponent<PlayerCharacter>();
    144.         }
    145.     }
    146.  
    147.     void OnDisable()
    148.     {
    149.         if (isLocalPlayer && Camera.main != null)
    150.         {
    151.             GetComponent<Camera>().enabled = true;
    152.             GetComponentInChildren<Camera>().enabled = true;
    153.         }
    154.     }
    155.  
    156.     // Update is called once per frame
    157.     void Update()
    158.     {
    159.         if (!isLocalPlayer || !_FPSWalker.enabled)
    160.             return;
    161.     }
    162.  
    163.     void FixedUpdate(){
    164.         if (!isLocalPlayer || _FPSWalker == null)
    165.             return;
    166.     }
    167. }
    168.  
    I know there are better ways to write this, but for now it will be ...
     
    Last edited: May 2, 2021
    Bioman75 and rainbowmirza like this.
  3. AzulineStudios

    AzulineStudios

    Joined:
    Feb 18, 2021
    Posts:
    18
    Thanks, that's a good suggestion llJIMBOBll. This feature has been added so ADS speed is adjustable per weapon.
     
    llJIMBOBll, rainbowmirza and Bioman75 like this.
  4. AzulineStudios

    AzulineStudios

    Joined:
    Feb 18, 2021
    Posts:
    18
    Hi ProBrStalker, it looks like this script is interfacing with an API of some sort. I edited the script to work on its own without errors. If you attach it to the root FPS Main object and uncheck the Remove Prefab Root box of the FPSPlayer.cs component, attached to the FPS Player object, it should find all the references.

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class NetworkBehavior : MonoBehaviour
    6. {
    7.     public Camera _MainCamera;
    8.     public Camera _WeaponCamera;
    9.     public FPSPlayer _FPSPlayerComponent;
    10.     public FPSRigidBodyWalker _FPSWalker;
    11.     public Ironsights _Ironsights;
    12.     public InputControl _InputControl;
    13.     public DragRigidbody _DragRigibody;
    14.     public PlayerWeapons _PlayerWeapons;
    15.     public GunSway _GunSway;
    16.     public WeaponEffects _WeaponEffects;
    17.     public CamAndWeapAnims _CamAndWeapAnims;
    18.     public ReconfigurePrefab _ReconfigurePrefab;
    19.     public SmoothMouseLook _SmoothMouseLook;
    20.     public Footsteps _Foootsteps;
    21.     public MovePlayerAndCamera _MovePlayerAndCamera;
    22.     public PlayerCharacter _PlayerCharacter;
    23.     public CameraControl _CameraControl;
    24.  
    25.     private bool hasAuthority = true;
    26.     private bool isLocalPlayer = true;
    27.  
    28.     void OnValidate()
    29.     {
    30.  
    31.         if (_MainCamera == null)
    32.             _MainCamera = GameObject.Find("Main Camera").GetComponent<Camera>();
    33.  
    34.         if (_WeaponCamera == null)
    35.             _WeaponCamera = GameObject.Find("Weapon Camera").GetComponent<Camera>();
    36.  
    37.         //!!!FPSCamera
    38.         if (_CamAndWeapAnims == null)
    39.             _CamAndWeapAnims = GetComponentInChildren<CamAndWeapAnims>();
    40.  
    41.         if (_ReconfigurePrefab == null)
    42.             _ReconfigurePrefab = GetComponentInChildren<ReconfigurePrefab>();
    43.  
    44.         if (_SmoothMouseLook == null)
    45.             _SmoothMouseLook = GetComponentInChildren<SmoothMouseLook>();
    46.  
    47.         if (_Foootsteps == null)
    48.             _Foootsteps = GetComponentInChildren<Footsteps>();
    49.  
    50.         if (_CameraControl == null)
    51.             _CameraControl = GetComponentInChildren<CameraControl>();
    52.  
    53.         //!!!FPSPlayer
    54.  
    55.         if (_FPSPlayerComponent == null)
    56.             _FPSPlayerComponent = GetComponentInChildren<FPSPlayer>();
    57.  
    58.         if (_FPSWalker == null)
    59.             _FPSWalker = GetComponentInChildren<FPSRigidBodyWalker>();
    60.  
    61.         if (_Ironsights == null)
    62.             _Ironsights = GetComponentInChildren<Ironsights>();
    63.  
    64.         if (_InputControl == null)
    65.             _InputControl = GetComponentInChildren<InputControl>();
    66.  
    67.         if (_DragRigibody == null)
    68.             _DragRigibody = GetComponentInChildren<DragRigidbody>();
    69.  
    70.         //!!!FPSWeapons
    71.  
    72.         if (_PlayerWeapons == null)
    73.             _PlayerWeapons = GetComponentInChildren<PlayerWeapons>();
    74.  
    75.         if (_GunSway == null)
    76.             _GunSway = GetComponentInChildren<GunSway>();
    77.  
    78.         if (_WeaponEffects == null)
    79.             _WeaponEffects = GetComponentInChildren<WeaponEffects>();
    80.  
    81.         //!!!VisibleBody
    82.  
    83.         if (_PlayerCharacter == null)
    84.             _PlayerCharacter = GetComponentInChildren<PlayerCharacter>();
    85.  
    86.         if (_MovePlayerAndCamera == null)
    87.             _MovePlayerAndCamera = GetComponentInChildren<MovePlayerAndCamera>();
    88.  
    89.     }
    90.  
    91.     void Start()
    92.     {
    93.  
    94.         _MainCamera.enabled = hasAuthority;
    95.         _WeaponCamera.enabled = hasAuthority;
    96.         {
    97.             Transform MaincameraTransform = _MainCamera.transform;
    98.             MaincameraTransform.parent = _MainCamera.transform;
    99.             MaincameraTransform.position = _MainCamera.transform.position;
    100.             MaincameraTransform.rotation = _MainCamera.transform.rotation;
    101.  
    102.             Transform WeaponCameraTransform = _WeaponCamera.transform;
    103.             WeaponCameraTransform.parent = _WeaponCamera.transform;
    104.             WeaponCameraTransform.position = _WeaponCamera.transform.position;
    105.             WeaponCameraTransform.rotation = _WeaponCamera.transform.rotation;
    106.  
    107.             //!!!FPSCamera
    108.             _CamAndWeapAnims.enabled = hasAuthority;
    109.             _CamAndWeapAnims.GetComponentInChildren<CamAndWeapAnims>();
    110.  
    111.             _ReconfigurePrefab.enabled = hasAuthority;
    112.             _ReconfigurePrefab.GetComponentInChildren<ReconfigurePrefab>();
    113.  
    114.             _SmoothMouseLook.enabled = hasAuthority;
    115.             _SmoothMouseLook.GetComponentInChildren<SmoothMouseLook>();
    116.  
    117.             _CameraControl.enabled = hasAuthority;
    118.             _CameraControl.GetComponentInChildren<CameraControl>();
    119.  
    120.             //!!!FPSPlayer
    121.  
    122.             _FPSWalker.enabled = isLocalPlayer;
    123.             _FPSWalker.GetComponentInChildren<FPSRigidBodyWalker>();
    124.  
    125.             _FPSPlayerComponent.enabled = hasAuthority;
    126.             _FPSPlayerComponent.GetComponentInChildren<FPSPlayer>();
    127.  
    128.             _Ironsights.enabled = hasAuthority;
    129.             _Ironsights.GetComponentInChildren<Ironsights>();
    130.  
    131.             _InputControl.enabled = hasAuthority;
    132.             _InputControl.GetComponentInChildren<InputControl>();
    133.  
    134.             _DragRigibody.enabled = hasAuthority;
    135.             _DragRigibody.GetComponentInChildren<DragRigidbody>();
    136.  
    137.             //!!!FPSWeapons
    138.  
    139.             _PlayerWeapons.enabled = hasAuthority;
    140.             _PlayerWeapons.GetComponentInChildren<PlayerWeapons>();
    141.  
    142.             _GunSway.enabled = hasAuthority;
    143.             _GunSway.GetComponentInChildren<PlayerWeapons>();
    144.  
    145.             _WeaponEffects.enabled = hasAuthority;
    146.             _WeaponEffects.GetComponentInChildren<WeaponEffects>();
    147.  
    148.             ///VisibleBody
    149.             _PlayerCharacter.enabled = hasAuthority;
    150.             _PlayerCharacter.GetComponent<PlayerCharacter>();
    151.         }
    152.     }
    153.  
    154.     void OnDisable()
    155.     {
    156.         if (isLocalPlayer && Camera.main != null)
    157.         {
    158.             GetComponentInChildren<Camera>().enabled = true;
    159.             GetComponentInChildren<Camera>().enabled = true;
    160.         }
    161.     }
    162.  
    163.     // Update is called once per frame
    164.     void Update()
    165.     {
    166.         if (!isLocalPlayer || !_FPSWalker.enabled)
    167.             return;
    168.     }
    169.  
    170.     void FixedUpdate()
    171.     {
    172.         if (!isLocalPlayer || _FPSWalker == null)
    173.             return;
    174.     }
    175. }
    176.  
    Another thing to keep in mind, the docs say that OnValidate() is only executed in the editor, so may need to change this script a bit more for runtime as I haven't tested it in a build. Hope that helps.
     
    ProBrStalker and Bioman75 like this.
  5. SickaGamer

    SickaGamer

    Joined:
    Jan 15, 2018
    Posts:
    1,092
    @AzulineStudios Hi! I just upgrade to 2019.5.25 and now I am getting an error on the FPS Player.

    UnassignedReferenceException: The variable aSource of TempAudioTimer has not been assigned.
    You probably need to assign the aSource variable of the TempAudioTimer script in the inspector.
    PlayAudioAtPos.PlayClipAt (UnityEngine.AudioClip clip, UnityEngine.Vector3 pos, System.Single vol, System.Single blend, System.Single pitch, System.Single minDist, System.Single maxDist) (at Assets/Systems/RFPSP/Scripts/Camera/PlayAudioAtPos.cs:20)
    FPSRigidBodyWalker.FixedUpdate () (at Assets/Systems/RFPSP/Scripts/Player/FPSRigidBodyWalker.cs:918)
     
  6. rainbowmirza

    rainbowmirza

    Joined:
    Jul 25, 2020
    Posts:
    15
    Hi,
    I'm using Control Freaks 2 (CF2) with RFPS foe mobile, how can I Adjust it so that It always sprints when player Moves forward with joystick.

     
  7. ProBrStalker

    ProBrStalker

    Joined:
    Aug 20, 2017
    Posts:
    21
    Thanks, azuline, as soon as this system is ready I will make it available here on the forum, as it is something even essential for RFPS
     
    Bioman75 likes this.
  8. ProBrStalker

    ProBrStalker

    Joined:
    Aug 20, 2017
    Posts:
    21

    upload_2021-5-6_22-6-38.png
    As you can see, I keep the main Player as a Network transform and I leave it configured to be the owner,

    and in the network animator, I put the visible body to be seen by the other players, but the problem is that when the player is instantiated, errors always occur ...

    maybe it is even better to use the BoltPlayer method, which is looking for transforms in the scene ...
     
    Bioman75 likes this.
  9. alonehuntert

    alonehuntert

    Joined:
    Oct 12, 2017
    Posts:
    11
    Hello, I wanted to add an inventory system to my game and it became the most preferred S-Inventory on the forum but it has been removed from the asset store of S-Inventory. Is there anywhere I can find S-Inventory? i really need it.







    AloneHuntert
     
  10. AzulineStudios

    AzulineStudios

    Joined:
    Feb 18, 2021
    Posts:
    18
    Hi, apologies for the delay in my response. In my testing, RFPS runs in Unity versions 2018 to 2020 without errors aside from the PostProcessing MinAttribute fix. It's possible that there was a change made that causes this error. You could try reimporting the RFPSP into a new Unity 2019 project and see if there is an error still? If not, you might want to start from the base RFPSP and add your changes gradually in the new version.

    If you change this code at line 936 in FPSRigidbodyWalker.cs, it should make the player run with move input :

    Code (CSharp):
    1.                 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    2.                 //Sprinting
    3.                 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    4.              
    5.                 if(allowSprinting){
    6.                     //toggle or hold sprinting state by determining if sprint button is pressed or held
    7.                     if((Mathf.Abs(inputY) > 0.0f && forwardSprintOnly) || (!forwardSprintOnly && (Mathf.Abs(inputX) > 0.0f) || Mathf.Abs(inputY) > 0.0f )){
    8.                         //if(InputComponent.sprintHold){
    9.                             if(!sprintStartState){
    10.                                 sprintStart = Time.time;//track time that sprint button was pressed
    11.                                 sprintStartState = true;//perform these actions only once
    12.                                 sprintEndState = false;
    13.                                 if(sprintEnd - sprintStart < sprintDelay * Time.timeScale){//if button is tapped, toggle sprint state
    14.                                     if(!sprintActive){
    15.                                         if(!sprintActive){//only allow sprint to start or cancel crouch if player is not under obstacle
    16.                                             sprintActive = true;
    17.                                         }else{
    18.                                             sprintActive = false;//pressing sprint button again while sprinting stops sprint
    19.                                         }
    20.                                     }else{
    21.                                         sprintActive = false;  
    22.                                     }
    23.                                 }
    24.                             }
    25.                         }else{
    26.                             if(!sprintEndState){
    27.                                 sprintEnd = Time.time;//track time that sprint button was released
    28.                                 sprintEndState = true;
    29.                                 sprintStartState = false;
    30.                                 if(sprintEnd - sprintStart > sprintDelay * Time.timeScale){//if releasing sprint button after holding it down, stop sprinting
    31.                                     sprintActive = false;  
    32.                                 }
    33.                             }
    34.                         }
    35.                     //}else{
    36.                     //    if(!InputComponent.sprintHold){
    37.                     //        sprintActive = false;
    38.                     //    }
    39.                     //}
    40.                 }
    Sounds like you're making progress ProBrStalker. You might need to change the way that the scripts pass references to PlayerCharacter.cs, which animates the third person character. Hope that helps.

    Hi, yes S-Inventory was a great asset. Maybe you can contact the original developer?


    As far as news on the new FPS asset, it is 95% complete, but I am still working out the feature set and support details. Sorry to keep you guys waiting, but this has pushed the release date back a bit. Thanks for your patience.
     
    Bioman75, Mark_01 and SickaGamer like this.
  11. SickaGamer

    SickaGamer

    Joined:
    Jan 15, 2018
    Posts:
    1,092
    @AzulineStudios Yeah I had to reimport it. Something got messed up when I tried upgrading to a newer version of Unity 2020.3. Good thing I took a backup and I just restored to a newer version of 2019.4. If I am not using HRP 2019.4 works just well for what I am doing. I hope things with the new asset are coming along! I can't wait to see what the future holds, just keep in mind that a few of us liked the old RFPS because of its ability to also do RPG games. You snap in melee skills/bow stuff mixed in with guns (think one shot muskets) along with an RPG style inventory, storage, gear and vendors...instant sale "Buy Now". I like doing FPS shooters as welll...so it would cover a lot of different genres! :)
     
  12. ProBrStalker

    ProBrStalker

    Joined:
    Aug 20, 2017
    Posts:
    21
    Guys, what is the responsible script that does when the character equips a weapon he raises his arms in the position of wielding one?
     
  13. alonehuntert

    alonehuntert

    Joined:
    Oct 12, 2017
    Posts:
    11
    Hello, I wrote to sinventorye developer 1 month ago and it hasn't seen or responded to my messages for 1 month. I have not been able to improve my game for 1 month since there is no inventory system. Please I need the Sinventory system.
    Can anyone send me the Sinventory unitypackage?
     
  14. ordinarycat

    ordinarycat

    Joined:
    Sep 30, 2020
    Posts:
    6
    That would be piracy. Unfortunately, you may have to create your own inventory system or find another one that suits your needs.
     
  15. SickaGamer

    SickaGamer

    Joined:
    Jan 15, 2018
    Posts:
    1,092
    @AzulineStudios Thanks for making RFPS! Attached below is my 1st game trailer. I will DEFINATELY buy your new one when it comes out!

     
  16. llJIMBOBll

    llJIMBOBll

    Joined:
    Aug 23, 2014
    Posts:
    578
  17. ProBrStalker

    ProBrStalker

    Joined:
    Aug 20, 2017
    Posts:
    21
    Hi guys, how can I access FPSPlayer's void Die in another script?

    In this case, I would like to make this void activate, after one of my vehicles explodes, in this case, to kill the player, and respawn him...
     
  18. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    11,386
    What if you just make the explosion do an amount of damage guaranteed to kill the player?
     
unityunity