Search Unity

Realistic FPS Prefab [RELEASED]

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

  1. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,697
    You're going to be a scripting pro pretty soon with all the modding you're doing. :)

    You're absolutely correct about the custom editor. You'll have to modify Emerald_Animal_AI_Editor.cs to include your new events. BHS is usually pretty responsive on their Unity forum thread. If you can get them to add these events, that would be the best solution because you won't lose them when you update Emerald AI.

    In the meantime, here's how to add them to Emerald_Animal_AI_Editor.cs. Find the OnInspectorGUI() method, and add the lines indicated below:
    Code (csharp):
    1. public override void OnInspectorGUI ()
    2. {
    3.     temp.Update ();
    4.     // ADD THE LINES BELOW:
    5.     EditorGUILayout.PropertyField(temp.FindProperty("onFlee"), true);
    6.     EditorGUILayout.PropertyField(temp.FindProperty("onFleeStop"), true);
    7.     EditorGUILayout.PropertyField(temp.FindProperty("onBreed"), true);
    8.     EditorGUILayout.PropertyField(temp.FindProperty("onHuntMode"), true); // etc...
    9.     // (END OF LINES TO ADD)
    10.     ...
    This will add the events at the top of the inspector. You can put those lines at the bottom of the OnInspectorGUI() method if you want them to appear at the bottom of the inspector.
     
  2. Weblox

    Weblox

    Joined:
    Apr 11, 2016
    Posts:
    277
    Awesome ! Thank you so much for the instant help.

    Haha. Thanks a bunch. I'll keep my fingers crossed...

    Yes, they have been abscent for some days and I have started wondering. They might be quite busy atm as they are working on releasing new updates I guess.

    Thanks a lot. I will try these out right away. It's always so impressive on how fast you are solving these kind of Issues. Just returned with a cup of coffee... ;)

    I let you know about my progress. Thanks for all the help.

    EDIT: Got it applied already with instant success. Initial Testrun has been working great with triggering Effects when NPC got hurt. I will try to contact BHS again and hope they will include this by default. :)

    Thanks again,
    Weblox
     
    Last edited: Mar 8, 2017
    TonyLi likes this.
  3. canaljuegos32

    canaljuegos32

    Joined:
    Jun 29, 2015
    Posts:
    63
    It is posible to make different weapon trails to each weapon by loading a prefab?
     
  4. emperor12321

    emperor12321

    Joined:
    Jun 21, 2015
    Posts:
    52
    This asset has been my main framework for almost two years of development, and 1.24 was a game changing update. It's almost a year from that and I haven't really seen anything of a next update. I just want to know if I should be keep hoping. Anyone know anything that I don't?
     
  5. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,697

    Asset Store

    Manual | Demo | Extras

    The Save System for RFPSP is now on the Asset Store! This easy-to-use add-on for Azuline Studios' Realistic FPS Prefab saves the information listed below in saved games and when changing scenes:
    • Player’s stats, inventory, position, and current scene
    • NPCs’ alive/dead state and position
    • State of pickups and destructibles
    • Objects dropped into the scene
    It also includes:
    • Scene change portals
    • Checkpoint save triggers
    • Ability to save to PlayerPrefs or encrypted disk files
    • Complete, thoroughly-documented C# source code
    It does not include a menu system, but the manual does contain simple instructions to add "Load Game" and "Save Game" buttons to RFPSP's main menu.

    If you already use the Dialogue System for Unity in your project, you do not need this.

    This is essentially an inexpensive ($10) copy of the Dialogue System's save functionality for RFPSP, but made really lightweight and easy to set up.
     
    Last edited: Mar 9, 2017
    chelnok, Weblox and Hormic like this.
  6. Hormic

    Hormic

    Joined:
    Aug 12, 2014
    Posts:
    251
    I find it quit annoying that i can slide the npc chars around just by walking in them,
    and in some circumstances it is also possible to push them in objects, like on the picture.

    Unity_2017-03-02_14-45-46.jpg

    The solution i thought about is to turn temporary off the NavMeshAgent to prevent this behavoir, at least for friendly NPCs.
    Is this the proper way, or is there a better solution?
     
  7. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,697
    EDIT: I dug into the code and found a better way. Please see my next post.

    Was:
    That's one way. You could add an Update() method to AI.cs that disables the NavMeshAgent when the player isn't moving for a duration (e.g., 0.5 seconds). In the TravelToPoint() method, re-enable the NavMeshAgent before setting the destination.

    However, I think a better way would be to make the NPC move out of the way. For example, if the player collides with the NPC, make the NPC choose a random location to the left or right, and set the navigation destination there.
     
    Last edited: Mar 10, 2017
    Hormic and Weblox like this.
  8. Weblox

    Weblox

    Joined:
    Apr 11, 2016
    Posts:
    277
    Awesome! This System is a great Addon for RFPS. Its effective and easy to use.I can only encourage everyone to get it for your game. Approvel has taken some time but now we are saved (!)... ;)
     
    Hormic and TonyLi like this.
  9. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,697
    In the AI script's StandWatch() method, comment out the code block that starts with the command:
    Code (csharp):
    1. //allow player to push friendly NPCs out of their way
    Alternatively, I threw together a starter script that makes the NPC move away when the player is too close. It may need some tweaking, but it's a start. Add it to the main NPC GameObject.

    AvoidPlayer.cs
    Code (csharp):
    1. using UnityEngine;
    2.  
    3. public class AvoidPlayer : MonoBehaviour
    4. {
    5.  
    6.     public float checkFrequency = 1;
    7.     public float tooCloseDistance = 3;
    8.     public float safeDistance = 5;
    9.     public float avoidDuration = 3;
    10.  
    11.     private AI m_ai;
    12.     private Transform m_playerTransform;
    13.     private float m_sidestepTime = 0;
    14.  
    15.     private void Awake()
    16.     {
    17.         m_ai = GetComponent<AI>();
    18.         m_playerTransform = GameObject.FindGameObjectWithTag("Player").transform;
    19.     }
    20.  
    21.     private void Update()
    22.     {
    23.         if (m_sidestepTime > 0)
    24.         {
    25.             m_sidestepTime -= Time.deltaTime;
    26.         }
    27.         else if (Vector3.Distance(transform.position, m_playerTransform.position) < tooCloseDistance)
    28.         {
    29.             m_sidestepTime = avoidDuration;
    30.             var newPosition = transform.position + safeDistance * Vector3.left;
    31.             m_ai.GoToPosition(newPosition, true);
    32.         }
    33.     }
    34.  
    35. }
     
    Hormic and Weblox like this.
  10. Hormic

    Hormic

    Joined:
    Aug 12, 2014
    Posts:
    251
    Wow, this is amazing, thank you TonyLi!!
    Don't know if it will also work, when you want to talk to npcs, could be that they are try to escape permanently :D. I have to experiment with this. :)
     
    Last edited: Mar 10, 2017
  11. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,697
    You'll have to adjust the distances. With the default values, if the player is closer than 3 units away the NPC will move away. Here's another idea: you could check if the player is moving, and only make the NPC move away if the player is moving. If the player is standing still, the NPC can stay put.
     
    Hormic likes this.
  12. TheChairMaster64

    TheChairMaster64

    Joined:
    Aug 9, 2016
    Posts:
    59
    So I've run into a problem let's say I wanted a main menu or a cut scene. It freezes everything with normal cameras. I even set a cube up with a rigidbody in front of a normal camera when I pressed play it did not fall. How do you fix this?
     
  13. Deki3d-Virus

    Deki3d-Virus

    Joined:
    Dec 11, 2012
    Posts:
    25
    How to Save Weapons when changing scenes ?
     
  14. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,697
    It's a bit complicated and requires some custom scripting. To help out Realistic FPS Prefab users, I wrote an asset (Save System for RFPSP) and put it on the Asset Store for cheap. It doesn't require any scripting.
     
    Mark_01 likes this.
  15. Deki3d-Virus

    Deki3d-Virus

    Joined:
    Dec 11, 2012
    Posts:
    25
    When i use DontDestroyOnLoad i have problem on player restart

    MissingReferenceException: The object of type 'Transform' has been destroyed but you are still trying to access it.
    Your script should either check if it is null or you should not destroy the object.
     
  16. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,697
    Don't use DontDestroyOnLoad. When the player scripts start, they look up things in the scene and cache references to them. When you reload, those cached references will no longer be valid since they refer to instances in the old version of the scene. Instead, before leaving a scene record what weapons and ammo the player has (and probably also health, hunger, thirst, etc.). When you enter a new scene, allow the player prefab in that scene to start up, and then apply the values that you recorded.
     
  17. Deki3d-Virus

    Deki3d-Virus

    Joined:
    Dec 11, 2012
    Posts:
    25

    I Save my hunger, health,thirst in playerprefs but i dont know how to save my weapons in playerprefs
     
  18. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,697
    Saving weapons isn't too bad. Find all the WeaponBehavior scripts that are children of FPS Weapons, and record their "Have" bool, ammo, and bullets left. The hard part is restoring weapons. You need to set it back up, run the PlayerWeapons.SelectWeapon(#) coroutine, and call PlayerWeapons.UpdateTotalWeapons(). You'll also want to update the GUIText values. It's kind of messy, which is why I made the Save System available.
     
  19. TheChairMaster64

    TheChairMaster64

    Joined:
    Aug 9, 2016
    Posts:
    59
    The camera thing I asked was not given a answer can it not be done? I also just ran into a weird problem with my AI they seem to miss hits on the player very often like 92% of 100 they will miss there attack but I haven't messed with the AI at all
     
  20. petercoleman

    petercoleman

    Joined:
    Feb 21, 2016
    Posts:
    477
    There is a setting in an enemy NPC properties to control the level of accuracy of their weapon and you should also have a similar setting for the Player weapons so you can adjust to make your game and NPCs more varied and interesting.

    The camera thing : I believe there is also a way to set up a cut scene using an available RFPSP camera, though I have no idea how to set it up as have never tried it. I think there is reference to these things in the Manual though don't know if that's very helpful to you.

    At the moment I do not have access to my RFPSP install as I am away in another country 6000 miles away from my home so cant help any further with more accurate details.

    I am sure someone else here can help you better than I :)

    Regards

    Peter
     
  21. Hormic

    Hormic

    Joined:
    Aug 12, 2014
    Posts:
    251
    On the FPS Camera there is a script which is called Move Player and Camera.
    You can activate it (but i guess it only works if show helptext on the FPS-Player is also active, this seems like a little bug)
    and then you can test it with the keys - insert for move player with camera
    delete - for releasing the main camera for cinematics and
    end - for releasing the main camera and reposition player
    but i'm also no expert, so please search for MovePlayerAndCamera in this thread und you will find more information.
     
  22. TheChairMaster64

    TheChairMaster64

    Joined:
    Aug 9, 2016
    Posts:
    59
    Thanks very much for the info. Has anyone had problems with there enemies not hitting the main character?
     
  23. Firesoft

    Firesoft

    Joined:
    Dec 20, 2016
    Posts:
    308
    Is Azuline responding to anyone? Or does anyone know a release date?
     
  24. Deki3d-Virus

    Deki3d-Virus

    Joined:
    Dec 11, 2012
    Posts:
    25
    Can u save weapons with Dialogue System?
     
  25. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,697
    Yes, you can save weapons with the Dialogue System and with the Save System for RFPS. They're two separate products. If you have the Dialogue System, you don't need to the Save System for RFPS. But if you don't need a full dialogue and quest system, the Save System for RFPS is smaller and cheaper.
     
    Mark_01 likes this.
  26. petercoleman

    petercoleman

    Joined:
    Feb 21, 2016
    Posts:
    477
    The developers don't seem to frequent this user forum to comment on the product or users questions. There is no regular feedback or support here or at their web site or updated Road Map or regular development progress reporting so one has to live in hope that it is going on in the background and that someday perhaps if you are lucky an Update will happen or not as the case may be.

    Thankfully there are some very kind users here who are prepared to help others by answering questions but I don't think they have any knowledge of any development or update news.
     
  27. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,697
    I did talk with Azuline to get their blessing for the Save System for RFPS, and they confirmed that they're hard at work on the next version. In fact, it might be released in the next few weeks.
     
    Mark_01, Weblox and Hormic like this.
  28. Hormic

    Hormic

    Joined:
    Aug 12, 2014
    Posts:
    251
    My wish would be, if they can make a normal hand model which can be easily changed with different textures.
    Not everyone needs a military hero for there game.
    I'm absolutely not and i tried to change the textures to get rid of the handgloves, but they gloves are not only in the texture they are also in the mesh itself, so no way to get rid of it easily, only way is to change the complete hand model.
    So this is my hope for the next version.

    Sidenote:
    It would be really nice if Azuline could be a bit more visible and tangible, cause it is annoying to work with an asset as the mainengine for a game, when the developers are completely submerged. So big thanks to TonyLi, otherwise this asset appears forsaken.
     
    Last edited: Mar 18, 2017
    Weblox likes this.
  29. jadorks

    jadorks

    Joined:
    Jul 11, 2016
    Posts:
    10
    I was hoping if anyone knew how to get Rfpsp working with Unet or Photon Pun Free. I don't want to purchase Bolt either. Or at least the version that would likely have multiplayer. Also does anyone have access to the v.1.24 version notes. Thank You
     
  30. jadorks

    jadorks

    Joined:
    Jul 11, 2016
    Posts:
    10
    I also ran into this problem. Try reducing their inaccuracy to 0 and see what happens.
     
  31. Devistute

    Devistute

    Joined:
    Aug 23, 2014
    Posts:
    32
    How can i release the mouse cursor without setting the timescale to zero?
    I have an system that lets you examine objects, and rotate them around but its not exactly best that the mouse is invinsible and centered to the screen. Is there any messages i can send to the scripts to release the cursor?
     
  32. Hormic

    Hormic

    Joined:
    Aug 12, 2014
    Posts:
    251
    Sorry i can't help you really but the Dialogue System provides functionality and scripts for this behavior.
    So maybe TonyLi can guide you further.
    I'm curious which examine System are you using?
    I would also have use for such system.
     
  33. Devistute

    Devistute

    Joined:
    Aug 23, 2014
    Posts:
    32
    Its mostly home-made, and uses playMaker for activating stuff & playing animations.
    Basically we have child object in the camera, and when one picks up say a note, it activates that object with fancy fade in and shuts down player input. Then it activates depth of field to blur the background, and thats pretty much it.

    The object that is examined, has the script for rotating it around when holding mouse button, and the mode can be exited by pressing esc.

    Main reason for the need of releasing mouse, is that for example in note there is key taped to the backside.
    And player can click it and get that key.
     
  34. Hormic

    Hormic

    Joined:
    Aug 12, 2014
    Posts:
    251
    Ahh yes, thank you for this detailed description. :)
     
  35. Devistute

    Devistute

    Joined:
    Aug 23, 2014
    Posts:
    32
    Incase anyone wants to see it in action, i made short video of it :)

     
  36. TheChairMaster64

    TheChairMaster64

    Joined:
    Aug 9, 2016
    Posts:
    59
    See my enemies are quite accurate already and in other scenes they work fine at putting out damage but in my recent level the first room of enemies hurt the player enough where its noticeable but when I go to the next room up stairs they just don't do much. They will stop at the range they can attack you from but they will not ever hit you unless you come chest to chest with them or you lean side to side but they can't hit you if you just stand still. And the enimes work perfect everyelse except 80% of my new level.
     
  37. TheChairMaster64

    TheChairMaster64

    Joined:
    Aug 9, 2016
    Posts:
    59
    Ok so I figured out the problem. It was a elevator so some how standing on it completely broke my enemies accuracy. I won't be using elevator now unless I animate it myself but I intended to do that anyway. I've always had problems with the elevator in rfps. Thanks for the suggestions tho
     
  38. TheChairMaster64

    TheChairMaster64

    Joined:
    Aug 9, 2016
    Posts:
    59
    Can some please fully explain how the move player and camera script really works in a dumbed down way cuz I don't think I understand. Thank you.
     
  39. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,697
    If you enable the MovePlayerAndCamera script, you can press these keys to see how it works:
    • Insert: Moves the player to the position of the GameObject you've assigned to Move Pos. Works by calling the script's MovePlayer() method.
    • Delete: Releases RFPS's control of the main camera and moves it to the position of the GameObject you've assigned to Cinema Camera Obj. At this point you can move the camera around using your own scripts or a cutscene editor such as SLATE or Cinema Director. If you press Delete again, RFPS will regain camera control. Works by calling the script's ReleaseMainCamera() method.
    • End: Works the same as Delete, except it also frees up the player object to be controlled outside of RFPS. Works by calling the script's ReleaseMainCameraAndMovePlayer() method.
    Azuline left the Update method in the script for people to be able to test out these methods. In your own project, you should probably comment out the entire Update method so players can't do the same thing.

    So let's say you want to make a cutscene that controls the camera. At the beginning of the cutscene, call the script's ReleaseMainCamera() method. At the end of the cutscene, call the same method again to give control back to RFPS.
     
    Weblox likes this.
  40. TheChairMaster64

    TheChairMaster64

    Joined:
    Aug 9, 2016
    Posts:
    59
    Thanks again tony this info helps a lot. My game might have a demo build out soon which is episode 0 where you play through E0M1-E0M4. I'll only post it here if you guys don't mind but if you do I wont. Thanks again :)
     
    TonyLi likes this.
  41. Devistute

    Devistute

    Joined:
    Aug 23, 2014
    Posts:
    32
    Has there been any news of the possible Mecanim Controller? Going with legacy animations is tricky since you cant make only upper part of body to interact with stuff etc, and playing custom animations just jerk in place.

    And i still need help about releasing the mouse cursor, i have been digging in the scripts and found none "legit" way to do this.
     
  42. jons190

    jons190

    Joined:
    Sep 13, 2016
    Posts:
    260
    Hi all! I am trying to integrate Rewired with RFPS (and the Dialogue System on top of everything) The standard input controllers doesn't seem to work well on Android in VR, so I wanted to try Rewired. It comes highly recommended from a couple of other VR/android devs. Anyway, I am fairly noobish when it comes to C# tried walking through these directions (a couple times) and am getting a parsing error when I add these to inputControl.cs. (in mondo It throws at an error at line 241 and says "} expected"

    I'm wading through the code now trying to figure out where/how to close the error, but was wondering if someone much more experienced then I could have a gander at the code and see where I am off.

    Unity: 5.4.of3
    RFPS 1.24
    Rewired trial

    My code:


    Code (csharp):
    1.  
    2. //InputControl.cs by Azuline Studios© All Rights Reserved
    3. //Manages button and axis input to be read by the other scripts.
    4. using UnityEngine;
    5. using System.Collections;
    6. using Rewired;
    7. public class InputControl : MonoBehaviour {
    8.  
    9.     private FPSPlayer FPSPlayerComponent;
    10. // rewired specific additions
    11. public int RewiredPlayerId = 0; // The Rewired player id of this character
    12. private Rewired.Player Rewiredplayer; // The Rewired Player
    13.  
    14.     //button states that are accessed by the other scripts
    15.     [HideInInspector]
    16.     public bool fireHold;
    17.     [HideInInspector]
    18.     public bool firePress;
    19.     [HideInInspector]
    20.     public bool reloadPress;
    21.     [HideInInspector]
    22.     public bool fireModePress;
    23.     [HideInInspector]
    24.     public bool jumpHold;
    25.     [HideInInspector]
    26.     public bool jumpPress;
    27.     [HideInInspector]
    28.     public bool crouchHold;
    29.     [HideInInspector]
    30.     public bool proneHold;
    31.     [HideInInspector]
    32.     public bool sprintHold;
    33.     [HideInInspector]
    34.     public bool zoomHold;
    35.     [HideInInspector]
    36.     public bool zoomPress;
    37.     [HideInInspector]
    38.     public bool leanLeftHold;
    39.     [HideInInspector]
    40.     public bool leanRightHold;
    41.     [HideInInspector]
    42.     public bool useHold;
    43.     [HideInInspector]
    44.     public bool usePress;
    45.     [HideInInspector]
    46.     public bool usePressUp;
    47.     [HideInInspector]
    48.     public bool toggleCameraHold;
    49.     [HideInInspector]
    50.     public bool toggleCameraDown;
    51.     [HideInInspector]
    52.     public bool grenadeHold;
    53.     [HideInInspector]
    54.     public bool deadzonePress;
    55.     [HideInInspector]
    56.     public bool meleePress;
    57.     [HideInInspector]
    58.     public bool flashlightPress;
    59.     [HideInInspector]
    60.     public bool holsterPress;
    61.     [HideInInspector]
    62.     public bool dropPress;
    63.     [HideInInspector]
    64.     public bool bulletTimePress;
    65.     [HideInInspector]
    66.     public bool moveHold;
    67.     [HideInInspector]
    68.     public bool movePress;
    69.     [HideInInspector]
    70.     public bool throwHold;
    71.     [HideInInspector]
    72.     public bool helpPress;
    73.     [HideInInspector]
    74.     public bool menuPress;
    75.     [HideInInspector]
    76.     public bool pausePress;
    77.     [HideInInspector]
    78.     public bool selectNextPress;
    79.     [HideInInspector]
    80.     public bool selectPrevPress;
    81.     [HideInInspector]
    82.     public bool selectGrenPress;
    83.     [HideInInspector]
    84.     public bool selectWeap1Press;
    85.     [HideInInspector]
    86.     public bool selectWeap2Press;
    87.     [HideInInspector]
    88.     public bool selectWeap3Press;
    89.     [HideInInspector]
    90.     public bool selectWeap4Press;
    91.     [HideInInspector]
    92.     public bool selectWeap5Press;
    93.     [HideInInspector]
    94.     public bool selectWeap6Press;
    95.     [HideInInspector]
    96.     public bool selectWeap7Press;
    97.     [HideInInspector]
    98.     public bool selectWeap8Press;
    99.     [HideInInspector]
    100.     public bool selectWeap9Press;
    101.     [HideInInspector]
    102.     public bool selectWeap0Press;
    103.    
    104.     [HideInInspector]
    105.     public float mouseWheel;
    106.    
    107.     [HideInInspector]
    108.     public bool leftHold;
    109.     [HideInInspector]
    110.     public bool rightHold;
    111.     [HideInInspector]
    112.     public bool forwardHold;
    113.     [HideInInspector]
    114.     public bool backHold;
    115.     [HideInInspector]
    116.     public float moveXButton;
    117.     [HideInInspector]
    118.     public float moveYButton;
    119.    
    120.     //gamepad input axes
    121.     [HideInInspector]
    122.     public float deadzone = 0.25f;
    123.     private Vector2 moveInput;
    124.     private Vector2 lookInput;
    125.    
    126.     //combined button and axis inputs for moving
    127.     [HideInInspector]
    128.     public float moveX;
    129.     [HideInInspector]
    130.     public float moveY;
    131.     //combined button and axis inputs for looking
    132.     [HideInInspector]
    133.     public float lookX;
    134.     [HideInInspector]
    135.     public float lookY;
    136.    
    137.     //Xbox 360 dpad controls (button held)
    138.     [HideInInspector]
    139.     public bool xboxDpadLeftHold;
    140.     [HideInInspector]
    141.     public bool xboxDpadRightHold;
    142.     [HideInInspector]
    143.     public bool xboxDpadUpHold;
    144.     [HideInInspector]
    145.     public bool xboxDpadDownHold;
    146.    
    147.     //Xbox 360 dpad controls (button press)
    148.     [HideInInspector]
    149.     public bool xboxDpadLeftPress;
    150.     [HideInInspector]
    151.     public bool xboxDpadRightPress;
    152.     [HideInInspector]
    153.     public bool xboxDpadUpPress;
    154.     [HideInInspector]
    155.     public bool xboxDpadDownPress;
    156.    
    157.     private bool xbdpLstate;
    158.     private bool xbdpRstate;
    159.     private bool xbdpUstate;
    160.     private bool xbdpDstate;
    161.  
    162.     void Awake() {
    163.          Rewiredplayer = ReInput.players.GetPlayer(RewiredPlayerId);
    164.      }
    165.    
    166.     void Start () {
    167.         FPSPlayerComponent = GetComponent<FPSPlayer>();
    168.     }
    169.    
    170.     void Update () {
    171.  
    172.         if(FPSPlayerComponent && !FPSPlayerComponent.restarting){
    173.        
    174. //player movement buttons
    175. leftHold = Rewiredplayer.GetButton("Left");
    176. rightHold = Rewiredplayer.GetButton("Right");
    177. forwardHold = Rewiredplayer.GetButton("Forward");
    178. backHold = Rewiredplayer.GetButton("Back");
    179.  
    180. moveInput = new Vector2(Rewiredplayer.GetAxis("Joystick Move X"), Rewiredplayer.GetAxis("Joystick Move Y"));
    181. lookInput = new Vector2(Rewiredplayer.GetAxis("Joystick Look X"), Rewiredplayer.GetAxis("Joystick Look Y"));
    182. lookX = Rewiredplayer.GetAxisRaw("Mouse X") + AccelerateInput(lookInput.x);
    183. lookY = Rewiredplayer.GetAxisRaw("Mouse Y") + AccelerateInput(lookInput.y);
    184.  
    185.             if (Rewiredplayer.GetAxisRaw ("Xbox R Trigger") > 0.1f || Rewiredplayer.GetButton ("Fire"))
    186.             if (Rewiredplayer.GetAxisRaw ("Xbox L Trigger") > 0.1f || Rewiredplayer.GetButton ("Zoom"))
    187.             if (Rewiredplayer.GetAxis ("Xbox Dpad X") > 0.0f) {
    188.  
    189.             } else if (Rewiredplayer.GetAxis ("Xbox Dpad X") < 0.0f) {
    190.  
    191.                 if (Rewiredplayer.GetAxis ("Xbox Dpad Y") > 0.0f) {
    192.                     if (Rewiredplayer.GetAxis ("Xbox Dpad Y") < 0.0f) {
    193.  
    194.                         mouseWheel = Rewiredplayer.GetAxis ("Mouse Scroll Wheel");
    195.                         firePress = Rewiredplayer.GetButtonDown ("Fire");
    196.                         zoomPress = Rewiredplayer.GetButtonDown ("Zoom");
    197.                         reloadPress = Rewiredplayer.GetButtonDown ("Reload");
    198.                         fireModePress = Rewiredplayer.GetButtonDown ("Fire Mode");
    199.                         jumpHold = Rewiredplayer.GetButton ("Jump");
    200.                         jumpPress = Rewiredplayer.GetButtonDown ("Jump");
    201.                         crouchHold = Rewiredplayer.GetButton ("Crouch");
    202.                         proneHold = Rewiredplayer.GetButton ("Prone");
    203.                         sprintHold = Rewiredplayer.GetButton ("Sprint");
    204.                         leanLeftHold = Rewiredplayer.GetButton ("Lean Left");
    205.                         leanRightHold = Rewiredplayer.GetButton ("Lean Right");
    206.                         useHold = Rewiredplayer.GetButton ("Use");
    207.                         usePress = Rewiredplayer.GetButtonDown ("Use");
    208.                         usePressUp = Rewiredplayer.GetButtonUp ("Use");
    209.  
    210.                         toggleCameraHold = Rewiredplayer.GetButton ("Toggle Camera");
    211.                         toggleCameraDown = Rewiredplayer.GetButtonDown ("Toggle Camera");
    212.                         grenadeHold = Rewiredplayer.GetButton ("Throw Grenade");
    213.                         meleePress = Rewiredplayer.GetButtonDown ("Melee Attack");
    214.                         flashlightPress = Rewiredplayer.GetButtonDown ("Toggle Flashlight");
    215.                         holsterPress = Rewiredplayer.GetButtonDown ("Holster Weapon");
    216.                         dropPress = Rewiredplayer.GetButtonDown ("Drop Weapon");
    217.                         bulletTimePress = Rewiredplayer.GetButtonDown ("Bullet Time");
    218.                         deadzonePress = Rewiredplayer.GetButtonDown ("Toggle Deadzone Aiming");
    219.                         helpPress = Rewiredplayer.GetButtonDown ("Help");
    220.                         menuPress = Rewiredplayer.GetButtonDown ("Main Menu");
    221.                         pausePress = Rewiredplayer.GetButtonDown ("Pause");
    222.  
    223.                         selectNextPress = Rewiredplayer.GetButtonDown ("Select Next Weapon");
    224.                         selectPrevPress = Rewiredplayer.GetButtonDown ("Select Previous Weapon");
    225.                         selectGrenPress = Rewiredplayer.GetButtonDown ("Select Next Grenade");
    226.                         selectWeap1Press = Rewiredplayer.GetButtonDown ("Select Weapon 1");
    227.                         selectWeap2Press = Rewiredplayer.GetButtonDown ("Select Weapon 2");
    228.                         selectWeap3Press = Rewiredplayer.GetButtonDown ("Select Weapon 3");
    229.                         selectWeap4Press = Rewiredplayer.GetButtonDown ("Select Weapon 4");
    230.                         selectWeap5Press = Rewiredplayer.GetButtonDown ("Select Weapon 5");
    231.                         selectWeap6Press = Rewiredplayer.GetButtonDown ("Select Weapon 6");
    232.                         selectWeap7Press = Rewiredplayer.GetButtonDown ("Select Weapon 7");
    233.                         selectWeap8Press = Rewiredplayer.GetButtonDown ("Select Weapon 8");
    234.                         selectWeap9Press = Rewiredplayer.GetButtonDown ("Select Weapon 9");
    235.                         selectWeap0Press = Rewiredplayer.GetButtonDown ("Select Weapon 0");
    236.  
    237.  
    238.                     } else {
    239.                         fireHold = false; //stop shooting if level is restarting
    240.                     }
    241.                 }
    242.             }
    243.    
    244.    
    245.     //accelerate axis input for easier control and reduction of axis drift (deadzone improvement)
    246.     float AccelerateInput(float input){
    247.         float inputAccel;
    248.         inputAccel = ((1.0f/4.0f) * input * (Mathf.Abs(input)*4.0f)) * Time.smoothDeltaTime * 60.0f;
    249.         return inputAccel;
    250.     }
    251.    
    252. }
    253.  
    am t
     
  43. jons190

    jons190

    Joined:
    Sep 13, 2016
    Posts:
    260
    Hi all! I am trying to integrate Rewired with RFPS (and the Dialogue System on top of everything) The standard input controllers doesn't seem to work well on Android in VR, so I wanted to try Rewired. It comes highly recommended from a couple of other VR/android devs. Anyway, I am fairly noobish when it comes to C# tried walking through these directions (a couple times) and am getting a parsing error when I add these to inputControl.cs. (in mondo It throws at an error at line 241 and says "} expected"

    I'm wading through the code now trying to figure out where/how to close the error, but was wondering if someone much more experienced then I could have a gander at the code and see where I am off.

    Unity: 5.4.of3
    RFPS 1.24
    Rewired trial

    My code:


    Code (csharp):
    1.  
    2. //InputControl.cs by Azuline Studios© All Rights Reserved
    3. //Manages button and axis input to be read by the other scripts.
    4. using UnityEngine;
    5. using System.Collections;
    6. using Rewired;
    7. public class InputControl : MonoBehaviour {
    8.  
    9.     private FPSPlayer FPSPlayerComponent;
    10. // rewired specific additions
    11. public int RewiredPlayerId = 0; // The Rewired player id of this character
    12. private Rewired.Player Rewiredplayer; // The Rewired Player
    13.  
    14.     //button states that are accessed by the other scripts
    15.     [HideInInspector]
    16.     public bool fireHold;
    17.     [HideInInspector]
    18.     public bool firePress;
    19.     [HideInInspector]
    20.     public bool reloadPress;
    21.     [HideInInspector]
    22.     public bool fireModePress;
    23.     [HideInInspector]
    24.     public bool jumpHold;
    25.     [HideInInspector]
    26.     public bool jumpPress;
    27.     [HideInInspector]
    28.     public bool crouchHold;
    29.     [HideInInspector]
    30.     public bool proneHold;
    31.     [HideInInspector]
    32.     public bool sprintHold;
    33.     [HideInInspector]
    34.     public bool zoomHold;
    35.     [HideInInspector]
    36.     public bool zoomPress;
    37.     [HideInInspector]
    38.     public bool leanLeftHold;
    39.     [HideInInspector]
    40.     public bool leanRightHold;
    41.     [HideInInspector]
    42.     public bool useHold;
    43.     [HideInInspector]
    44.     public bool usePress;
    45.     [HideInInspector]
    46.     public bool usePressUp;
    47.     [HideInInspector]
    48.     public bool toggleCameraHold;
    49.     [HideInInspector]
    50.     public bool toggleCameraDown;
    51.     [HideInInspector]
    52.     public bool grenadeHold;
    53.     [HideInInspector]
    54.     public bool deadzonePress;
    55.     [HideInInspector]
    56.     public bool meleePress;
    57.     [HideInInspector]
    58.     public bool flashlightPress;
    59.     [HideInInspector]
    60.     public bool holsterPress;
    61.     [HideInInspector]
    62.     public bool dropPress;
    63.     [HideInInspector]
    64.     public bool bulletTimePress;
    65.     [HideInInspector]
    66.     public bool moveHold;
    67.     [HideInInspector]
    68.     public bool movePress;
    69.     [HideInInspector]
    70.     public bool throwHold;
    71.     [HideInInspector]
    72.     public bool helpPress;
    73.     [HideInInspector]
    74.     public bool menuPress;
    75.     [HideInInspector]
    76.     public bool pausePress;
    77.     [HideInInspector]
    78.     public bool selectNextPress;
    79.     [HideInInspector]
    80.     public bool selectPrevPress;
    81.     [HideInInspector]
    82.     public bool selectGrenPress;
    83.     [HideInInspector]
    84.     public bool selectWeap1Press;
    85.     [HideInInspector]
    86.     public bool selectWeap2Press;
    87.     [HideInInspector]
    88.     public bool selectWeap3Press;
    89.     [HideInInspector]
    90.     public bool selectWeap4Press;
    91.     [HideInInspector]
    92.     public bool selectWeap5Press;
    93.     [HideInInspector]
    94.     public bool selectWeap6Press;
    95.     [HideInInspector]
    96.     public bool selectWeap7Press;
    97.     [HideInInspector]
    98.     public bool selectWeap8Press;
    99.     [HideInInspector]
    100.     public bool selectWeap9Press;
    101.     [HideInInspector]
    102.     public bool selectWeap0Press;
    103.    
    104.     [HideInInspector]
    105.     public float mouseWheel;
    106.    
    107.     [HideInInspector]
    108.     public bool leftHold;
    109.     [HideInInspector]
    110.     public bool rightHold;
    111.     [HideInInspector]
    112.     public bool forwardHold;
    113.     [HideInInspector]
    114.     public bool backHold;
    115.     [HideInInspector]
    116.     public float moveXButton;
    117.     [HideInInspector]
    118.     public float moveYButton;
    119.    
    120.     //gamepad input axes
    121.     [HideInInspector]
    122.     public float deadzone = 0.25f;
    123.     private Vector2 moveInput;
    124.     private Vector2 lookInput;
    125.    
    126.     //combined button and axis inputs for moving
    127.     [HideInInspector]
    128.     public float moveX;
    129.     [HideInInspector]
    130.     public float moveY;
    131.     //combined button and axis inputs for looking
    132.     [HideInInspector]
    133.     public float lookX;
    134.     [HideInInspector]
    135.     public float lookY;
    136.    
    137.     //Xbox 360 dpad controls (button held)
    138.     [HideInInspector]
    139.     public bool xboxDpadLeftHold;
    140.     [HideInInspector]
    141.     public bool xboxDpadRightHold;
    142.     [HideInInspector]
    143.     public bool xboxDpadUpHold;
    144.     [HideInInspector]
    145.     public bool xboxDpadDownHold;
    146.    
    147.     //Xbox 360 dpad controls (button press)
    148.     [HideInInspector]
    149.     public bool xboxDpadLeftPress;
    150.     [HideInInspector]
    151.     public bool xboxDpadRightPress;
    152.     [HideInInspector]
    153.     public bool xboxDpadUpPress;
    154.     [HideInInspector]
    155.     public bool xboxDpadDownPress;
    156.    
    157.     private bool xbdpLstate;
    158.     private bool xbdpRstate;
    159.     private bool xbdpUstate;
    160.     private bool xbdpDstate;
    161.  
    162.     void Awake() {
    163.          Rewiredplayer = ReInput.players.GetPlayer(RewiredPlayerId);
    164.      }
    165.    
    166.     void Start () {
    167.         FPSPlayerComponent = GetComponent<FPSPlayer>();
    168.     }
    169.    
    170.     void Update () {
    171.  
    172.         if(FPSPlayerComponent && !FPSPlayerComponent.restarting){
    173.        
    174. //player movement buttons
    175. leftHold = Rewiredplayer.GetButton("Left");
    176. rightHold = Rewiredplayer.GetButton("Right");
    177. forwardHold = Rewiredplayer.GetButton("Forward");
    178. backHold = Rewiredplayer.GetButton("Back");
    179.  
    180. moveInput = new Vector2(Rewiredplayer.GetAxis("Joystick Move X"), Rewiredplayer.GetAxis("Joystick Move Y"));
    181. lookInput = new Vector2(Rewiredplayer.GetAxis("Joystick Look X"), Rewiredplayer.GetAxis("Joystick Look Y"));
    182. lookX = Rewiredplayer.GetAxisRaw("Mouse X") + AccelerateInput(lookInput.x);
    183. lookY = Rewiredplayer.GetAxisRaw("Mouse Y") + AccelerateInput(lookInput.y);
    184.  
    185.             if (Rewiredplayer.GetAxisRaw ("Xbox R Trigger") > 0.1f || Rewiredplayer.GetButton ("Fire"))
    186.             if (Rewiredplayer.GetAxisRaw ("Xbox L Trigger") > 0.1f || Rewiredplayer.GetButton ("Zoom"))
    187.             if (Rewiredplayer.GetAxis ("Xbox Dpad X") > 0.0f) {
    188.  
    189.             } else if (Rewiredplayer.GetAxis ("Xbox Dpad X") < 0.0f) {
    190.  
    191.                 if (Rewiredplayer.GetAxis ("Xbox Dpad Y") > 0.0f) {
    192.                     if (Rewiredplayer.GetAxis ("Xbox Dpad Y") < 0.0f) {
    193.  
    194.                         mouseWheel = Rewiredplayer.GetAxis ("Mouse Scroll Wheel");
    195.                         firePress = Rewiredplayer.GetButtonDown ("Fire");
    196.                         zoomPress = Rewiredplayer.GetButtonDown ("Zoom");
    197.                         reloadPress = Rewiredplayer.GetButtonDown ("Reload");
    198.                         fireModePress = Rewiredplayer.GetButtonDown ("Fire Mode");
    199.                         jumpHold = Rewiredplayer.GetButton ("Jump");
    200.                         jumpPress = Rewiredplayer.GetButtonDown ("Jump");
    201.                         crouchHold = Rewiredplayer.GetButton ("Crouch");
    202.                         proneHold = Rewiredplayer.GetButton ("Prone");
    203.                         sprintHold = Rewiredplayer.GetButton ("Sprint");
    204.                         leanLeftHold = Rewiredplayer.GetButton ("Lean Left");
    205.                         leanRightHold = Rewiredplayer.GetButton ("Lean Right");
    206.                         useHold = Rewiredplayer.GetButton ("Use");
    207.                         usePress = Rewiredplayer.GetButtonDown ("Use");
    208.                         usePressUp = Rewiredplayer.GetButtonUp ("Use");
    209.  
    210.                         toggleCameraHold = Rewiredplayer.GetButton ("Toggle Camera");
    211.                         toggleCameraDown = Rewiredplayer.GetButtonDown ("Toggle Camera");
    212.                         grenadeHold = Rewiredplayer.GetButton ("Throw Grenade");
    213.                         meleePress = Rewiredplayer.GetButtonDown ("Melee Attack");
    214.                         flashlightPress = Rewiredplayer.GetButtonDown ("Toggle Flashlight");
    215.                         holsterPress = Rewiredplayer.GetButtonDown ("Holster Weapon");
    216.                         dropPress = Rewiredplayer.GetButtonDown ("Drop Weapon");
    217.                         bulletTimePress = Rewiredplayer.GetButtonDown ("Bullet Time");
    218.                         deadzonePress = Rewiredplayer.GetButtonDown ("Toggle Deadzone Aiming");
    219.                         helpPress = Rewiredplayer.GetButtonDown ("Help");
    220.                         menuPress = Rewiredplayer.GetButtonDown ("Main Menu");
    221.                         pausePress = Rewiredplayer.GetButtonDown ("Pause");
    222.  
    223.                         selectNextPress = Rewiredplayer.GetButtonDown ("Select Next Weapon");
    224.                         selectPrevPress = Rewiredplayer.GetButtonDown ("Select Previous Weapon");
    225.                         selectGrenPress = Rewiredplayer.GetButtonDown ("Select Next Grenade");
    226.                         selectWeap1Press = Rewiredplayer.GetButtonDown ("Select Weapon 1");
    227.                         selectWeap2Press = Rewiredplayer.GetButtonDown ("Select Weapon 2");
    228.                         selectWeap3Press = Rewiredplayer.GetButtonDown ("Select Weapon 3");
    229.                         selectWeap4Press = Rewiredplayer.GetButtonDown ("Select Weapon 4");
    230.                         selectWeap5Press = Rewiredplayer.GetButtonDown ("Select Weapon 5");
    231.                         selectWeap6Press = Rewiredplayer.GetButtonDown ("Select Weapon 6");
    232.                         selectWeap7Press = Rewiredplayer.GetButtonDown ("Select Weapon 7");
    233.                         selectWeap8Press = Rewiredplayer.GetButtonDown ("Select Weapon 8");
    234.                         selectWeap9Press = Rewiredplayer.GetButtonDown ("Select Weapon 9");
    235.                         selectWeap0Press = Rewiredplayer.GetButtonDown ("Select Weapon 0");
    236.  
    237.  
    238.                     } else {
    239.                         fireHold = false; //stop shooting if level is restarting
    240.                     }
    241.                 }
    242.             }
    243.    
    244.    
    245.     //accelerate axis input for easier control and reduction of axis drift (deadzone improvement)
    246.     float AccelerateInput(float input){
    247.         float inputAccel;
    248.         inputAccel = ((1.0f/4.0f) * input * (Mathf.Abs(input)*4.0f)) * Time.smoothDeltaTime * 60.0f;
    249.         return inputAccel;
    250.     }
    251.    
    252. }
    253.  
    am t
     
  44. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,697
    @jons190 - I'm heading out of the office for a few hours, but when I get back I'll take a look and post what I can. I've worked with all 3 products. :)
     
  45. jons190

    jons190

    Joined:
    Sep 13, 2016
    Posts:
    260
    T Li! You are the man! Thanks much.

    Edit: So I have worked through the Dialogue system and think I have a pretty good handle on it as a "stand alone" system... but have not gone through the RFPS integration yet. I noticed that in this code (the rewired= RFPS) it was mentioned that the author added a couple operators for integrating the Dsystem. (some calls for x and y movement) and makes me wonder how well all these plugins will play together and if there is some order I should follow for integration/optimization. (I'm deving for android/ gearVR so performance is always the number one consideration)

    I'm thinking getting rewired working first, then add the dialogue intergration after that? Would you think this is a good idea? Do you know of any "gotchas" on stringing all these of these applications together?

    Thanks in advance.
     
    Last edited: Mar 23, 2017
  46. magique

    magique

    Joined:
    May 2, 2014
    Posts:
    4,030
    I don't exactly all that is contained in your asset, but if you don't already have it, you should consider providing some sort of script that you can attach to any object that can save basic properties of. So if we want to save things that aren't specific to RFPS then we can simply attach the script to an object and your system would save and load the data. Maybe make it extensible so we can save/load custom properties.
     
  47. Gua

    Gua

    Joined:
    Oct 29, 2012
    Posts:
    455
    I've just updated my project that is using RFPS 1.21 to 5.52 and my character stopped moving. I've discovered that if I touch any parameter in Capsule Collider or Rigidbody in editor it starts to work. Like enabling and disabling kinematic, or removing and adding back physics material. But if I do it from the script it doesn't work, it works only when I touch it in inspector. Has anyone had this problem? Is there a solution?

    Looks like the problem is that otherwise grounded is set to false.

    Looks like changing p1, p2, capsule.radius * 0.90f.... to p1, p2, capsule.radius * 1.00f, -myTransform.up, out capHit, capsuleCastHeight * 1.5f helped at a test scene.
     
    Last edited: Mar 23, 2017
  48. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,697
    Here are the steps:

    1. Import Realistic FPS Prefab first. It's a Complete Project, so it wipes out Unity's input settings.

    2. Then import Rewired. When it installs, it will add its own values to Unity's input settings.

    3. Add ExtraInput.cs (from the Integration package or below). [EDIT: Just drop this file into your project. You don't need to add it to any GameObject in your scene.]

    4. Edit RFPSP/Scripts/Camera/CameraControl.cs and Player/InputControl.cs. In only these 2 files, global search and replace "Input." with "ExtraInput.", case-sensitive. (Rather than hard-code Rewired stuff directly in RFPSP's scripts, I wrote a bridge script called ExtraInput. ExtraInput currently calls Rewired, but users of other input systems such as InControl could just add their code instead.) EDIT: Make sure not to accidentally change "move.input.x", etc.; just "Input.".

    5. Add the Rewired Input Manager prefab in the Integration package to your scene, or create and define your own. (Window > Rewired > Create > Input Manager). I only mapped inputs for WASD and mouse look. You'll have to map the rest.

    The script is below. I'll also attach an integration package with this script and the Rewired Input Manager prefab. The prefab is just a starter. I added all the required input names, but I didn't map them to actual keys/buttons.

    ExtraInput.cs
    Code (csharp):
    1. using UnityEngine;
    2.  
    3. public static class ExtraInput
    4. {
    5.  
    6.     public const int PlayerId = 0;
    7.  
    8.     public static Rewired.Player rewiredPlayer
    9.     {
    10.         get
    11.         {
    12.             if (s_rewiredPlayer == null) s_rewiredPlayer = Rewired.ReInput.players.GetPlayer(PlayerId);
    13.             return s_rewiredPlayer;
    14.         }
    15.     }
    16.  
    17.     private static Rewired.Player s_rewiredPlayer = null;
    18.  
    19.     public static float GetAxis(string axisName)
    20.     {
    21.         return rewiredPlayer.GetAxis(axisName);
    22.     }
    23.  
    24.     public static float GetAxisRaw(string axisName)
    25.     {
    26.         return rewiredPlayer.GetAxisRaw(axisName);
    27.     }
    28.  
    29.     public static bool GetButton(string buttonName)
    30.     {
    31.         return rewiredPlayer.GetButton(buttonName);
    32.     }
    33.  
    34.     public static bool GetButtonDown(string buttonName)
    35.     {
    36.         return rewiredPlayer.GetButtonDown(buttonName);
    37.     }
    38.  
    39.     public static bool GetButtonUp(string buttonName)
    40.     {
    41.         return rewiredPlayer.GetButtonUp(buttonName);
    42.     }
    43. }

    Integrating with the Dialogue System is much easier. Use Unity UI, and use Rewired's Event System for Unity UI. That's it. If you want to implement a conversation-cancel button in Rewired, here's a tiny script to do that. You can take care of this after integrating RFPSP and Rewired. I'm not aware of any issues getting all 3 working together.
     

    Attached Files:

    Last edited: Mar 25, 2017
    Weblox likes this.
  49. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,697
    The Save System for RFPS is actually a general-purpose save system with a couple extra RFPS-specific components to handle RFPS data. To save anything, just create a subclass of the Saver class and override the RecordData() and ApplyData() methods.

    I'm guessing that, by touching the player prefab in the inspector, you're causing Unity to re-serialize it. As a side effect, it may update other properties, some of which are serialized but hidden from the inspector. (Azuline uses the [HideInInspector] attribute liberally to reduce clutter in the inspector.)
     
    magique likes this.
  50. jons190

    jons190

    Joined:
    Sep 13, 2016
    Posts:
    260
    Hey Tony. Thanks much for this. Say I have a question. I'm going through this and am on step 3.

    So where to add this exactly? Whenever I try to add it to a game object I get the following error message:

    "Can't add script behavior Extrainput. The script class cannot be abstract."

    I am clueless!