Search Unity

Realistic FPS Prefab [RELEASED]

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

  1. GhereGames

    GhereGames

    Joined:
    Mar 24, 2015
    Posts:
    23
    I'm working on a script that is a Modified version of AI.cs that comes with rFPS. I have the zombies able to wander and can set them to wander or hunt when the NPCSpanwer.cs script creates them. Is there a way to set them to hunt/wander based on a variable that the AI.cs script can read?

    I'd finally like to be able to have several behaviors they can switch between at runtime based on environment variables.
    Thank you
     
  2. petercoleman

    petercoleman

    Joined:
    Feb 21, 2016
    Posts:
    477
    I have some questions for TonyLi please if you can help regarding saving games and the Save System.

    I use the Portals to change and move through scenes and Save Checkpoints to save the state of the game. All works perfectly as far as I can see...

    I want to have a game player and myself while developing as it would be particularly helpful to be able to Save and Load scenes (and Player progress - Game state) at a time of choice via a Menu button also....

    I do not use the RFPSP menu (it has much that I don't want and does not have what I do want) but use a simple menu system currently which at the moment just has basic game functions. e.g. start game, pause game, quit game. I also have some buttons which have a simple unity event to load a specific level on click but these buttons have nothing to do with the PCrushers Save System.....I have for a long timer always had a non RFPSP Menu with load level/scene buttons.

    Question : I have the Checkpoint Saves set up all to use "Slot 0" and that seems to work fine but I am not sure that is correct and if each Checkpoint save in each different level should have different slot numbers. e.g Slot 1, Slot 2 and so on? As said seems to work fine as is all using slot 0 and that given that I have numerous checkpoints in each scene as it saves the Player game state as the player progresses there being only one save the last Checkpoint which seems to be correct to me....

    Question : Importantly as said I want to add Save scene to a menu button and thereafter be able to load a saved scene from the save slot via a second Load scene menu button...I also want to be able to save and load each scene individually rather than just one save of the last state saved as done now by the Checkpoint method....So I need a separate slot for each scene or save however following the PC save system manual it is unclear to me how to do this from the descriptions...

    As said previously under my current menu I can set up the standard loading of scenes and have done so for quite some time....

    In the PC Save system manual it says this :
    If you have a menu system, to load and save games you can assign the methods
    SaveSystem.SaveGameToSlot and SaveSystem.LoadGameFromSlot to your UI buttons’ OnClick()
    events....

    What I cant find or understand is the methods as described above. i.e. SaveSystem.SaveGameToSlot and SaveSystem.LoadGameFromSlot

    Where are or where do I find the methods above to assign?
    And how do I create or add separate slots to save and load levels to/from via menu buttons/slots?

    When creating load or save buttons in my menu I can only find the Unity Standard Event Load Scene on Click method to add?

    I do apologize for my ignorance and lack of understanding here and am sure I am a bit slow not knowing how to find what I need...

    Last Question : If one were to use menu buttons to save/load scenes would that cancel out the ability to also use the Save System Checkpoints? i.e. is it one or the other method?


    Thanks for any pointers or advice.

    Peter
     
  3. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,694
    Hi Peter,
    That's the way to do it. Use slot 0.

    Slots are just arbitrary numbers used to index saved games. In this scenario, I think it would make sense to use a different slot number for each scene, where the slot number corresponds to the scene's build index number. I'll provide more details later in this reply.

    They're on the Save System GameObject. Let's say you want to save a game to slot 42. Assign the Save System to your button's OnClick() event, select SaveSystem.SaveGameToSlot, and specify the slot number:



    Let's say you create 3 buttons labeled "Save in Slot 1", "Save in Slot 2", and "Save in Slot 3". Just hook up each button's OnClick() to SaveSystem.SaveGameToSlot, and specify 1, 2, or 3.

    Getting back to your first question, use a helper script to save to the slot number that corresponds to the current scene's build index number. You can use this script:

    SaveLoadBySceneNumber.cs
    Code (csharp):
    1. using UnityEngine;
    2.  
    3. public class SaveLoadBySceneNumber : MonoBehaviour
    4. {
    5.     public int GetSceneNumber()
    6.     {
    7.         return UnityEngine.SceneManagement.SceneManager.GetActiveScene().buildIndex;
    8.     }
    9.  
    10.     public void SaveToSceneNumberSlot()
    11.     {
    12.         PixelCrushers.SaveSystem.SaveToSlot(GetSceneNumber());
    13.     }
    14.  
    15.     public void LoadFromSceneNumberSlot()
    16.     {
    17.         PixelCrushers.SaveSystem.LoadFromSlot(GetSceneNumber());
    18.     }
    19. }

    Add the script to the Save System, and hook up your button to SaveLoadBySceneNumber.SaveToSceneNumberSlot:



    No, you can use both. If you want to load the last checkpoint (assuming you're saving checkpoints into slot 0):

     
  4. petercoleman

    petercoleman

    Joined:
    Feb 21, 2016
    Posts:
    477
    Hi Tony Li,

    Thank you for that most remarkably helpful reply....

    You are a Star. I would have been stuck with a lot of that especially the additional scripts :)

    I hate bothering you like this - hopefully this may also help other users too.

    Thank you again so much.

    Peter
     
  5. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,694
  6. TheMessyCoder

    TheMessyCoder

    Joined:
    Feb 13, 2017
    Posts:
    522
    MaliceA4Thought and TonyLi like this.
  7. philc_uk

    philc_uk

    Joined:
    Jun 17, 2015
    Posts:
    90
    Hi,
    When switched to 3rd person, and looking up in the sky while holding a rifle.. the character does not point up, he still kind of looks forwards and leans a bit, but firing does shoot in the right direction. Anybody got an approach to animate the character so they lean up to follow the mouse?

    Cheers
     
  8. petercoleman

    petercoleman

    Joined:
    Feb 21, 2016
    Posts:
    477
    Hi all,

    Anyone have a step by step overview of how to Spawn enemies/characters via the "Spawner". That is what would be a correct procedure/method? I do not need "Waves" just a simple spawn for individual characters that may spawn more than one or an infinite number with a delay....

    I have problems and always have using my "Custom" characters where spawners behave erratically. i.e. they never work as should....

    Default Characters (Soldier with Colliders) work as should so I don't know why custom characters don't as I have them set up using the same settings and so on and based upon the default Soldier character...

    When using custom Characters if I add a spawner - I break prefab instance and rename to my own then add my Character in the Object field....

    1. If I add a character from the RFPSP NPC Prefab at the moment and run the scene i get the NPC cant find navmesh - rebake or move closer to navmesh error and they don't spawn correctly. Now of course I can rebake the navmesh as many times as I like and move the NPC anywhere near or far from the navmesh surface as requested but it makes no difference and the error still occurs :)

    2. If I add a character from in scene to the spawner instead it does not error but if I say spawn 5 - when the last instance is killed thats it - as the last of the instances is killed the system of course cant spawn another as one does not exist so no more than the 5 will spawn?

    If use the default soldier as the spawn object from the NPC folder as said it works as needed and an unlimited number will continue to spawn at my specified wait times and so on correctly...

    I really cant find any difference between the default character models and my own visually or their set up in spawner and so on but clearly RFPSP or Unity does see something it does not like? Perhaps its my custom models?

    Anyway at the moment I can work with Spawning only default enemies say and use my custom characters for others but I would like to find a solution or at least understand the issues....

    I get do sometimes get erratic behaviours with custom characters following paths too so it may be the models I use?

    Thanks for any help.

    Peter
     
  9. evanvi1997

    evanvi1997

    Joined:
    Dec 3, 2017
    Posts:
    5
    Hi all,
    The reason I am writing this is to seek help for a problem I am having with the kit, which don't get me wrong I really like!. So basically, I purchased this kit about a month ago and I noticed that every time I import it to unity, it causes all sorts of random problems. For example the time-line preview doesn't work and the time-line in general. Also I can't view particles in the editor and sometimes they don't even appear during play mode. I really need help with this one, since I really like the kit and I wish to use it pleasantly. Thank you.
     
  10. jnbbender

    jnbbender

    Joined:
    May 25, 2017
    Posts:
    487
    I'm not sure the particle editor is caused by this kit. I haven't been able to do that either for some time now. Sorry about timeline - haven't used it yet.
     
  11. jnbbender

    jnbbender

    Joined:
    May 25, 2017
    Posts:
    487
    Question, most probably for TonyLi. I am about to put out my game but I'm having one last issue I cannot get around. When the player starts a new level they are given simple instructions by a dialogue system & voice...great. (SceneHandler.cs Start() calls Instructions.cs::Instruct()) to perform this function). But when the player loads a previously saved game the instructions play as well (which is how it is programmed). But this is annoying depending on where they left off. I am using TonyLi's Save System and the SceneHandler inherits from Saver.cs so I am overriding "ApplyData" to load the saved game.

    Finally my problem. How can I tell the difference between a brand new scene and a loaded scene? It seems as if the only way to hook into a "LoadedScene" event is with the SceneManager.sceneLoaded delegate but I won't be able to tell if I'm going to "ApplyData" to it, i.e. load up a previously saved game. If I know I'm gonna call "ApplyData" I can easily shutoff Instructions.
     
  12. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,694
    You'll want to use a prefab -- or, in the worst case, hide your original NPC GameObject where the player can't get to it. Things to check:
    • Your prefab has all the components that the RFPSP soldier does, such as NavMeshAgent, AI, etc.
    • The AI's Object With Anims has an Animator. (This is the child object "SoldierModelWithJoints" in the RFPSP soldier).
    • Your NPC's bone hiearchy has colliders, rigidbodies, and Location Damage scripts. See the RFPSP soldier's Pelvis child GameObject for an example.
    • Make sure the NPC's NavMeshAgent is positioned similarly to the NavMeshAgent on the RFPSP soldier and all the other settings are similar.

    The Save System gives the scene one frame to spin up, and then it applies saved data. In your SceneHandler, wait one frame and then check if ApplyData got called at the end of the second frame.

    Here's an example scene: ShowOnNewGameExample_2017-12-21.unitypackage

    And here's the script from the example scene:

    ShowOnNewGame.cs
    Code (csharp):
    1. using UnityEngine;
    2. using System.Collections;
    3. using PixelCrushers;
    4.  
    5. // This example script activates a GameObject (showThis) only
    6. // if *not* loading a saved game.
    7. public class ShowOnNewGame : Saver
    8. {
    9.     // Object to show on a new game:
    10.     public GameObject showThis;
    11.  
    12.     // Have we already showed it? (i.e., is this not a new game?)
    13.     public bool alreadyShowed = false;
    14.  
    15.     public override void Awake()
    16.     {
    17.         base.Awake();
    18.         showThis.SetActive(false); // Save inactive immediately.
    19.     }
    20.  
    21.     public override void Start()
    22.     {
    23.         base.Start();
    24.         StartCoroutine(ShowIfNotAlreadyShowed()); // Show if a new game.
    25.     }
    26.  
    27.     private IEnumerator ShowIfNotAlreadyShowed()
    28.     {
    29.         // On second frame, SaveSystem may call ApplyData. Wait for it:
    30.         yield return null;
    31.         yield return new WaitForEndOfFrame();
    32.  
    33.         if (!alreadyShowed)
    34.         {
    35.             showThis.SetActive(true);
    36.             alreadyShowed = true;
    37.         }
    38.     }
    39.  
    40.     public override string RecordData()
    41.     {
    42.         return alreadyShowed.ToString();
    43.     }
    44.  
    45.     public override void ApplyData(string data)
    46.     {
    47.         if (data == null) return;
    48.         alreadyShowed = bool.Parse(data);
    49.     }
    50.  
    51. }
     
  13. jnbbender

    jnbbender

    Joined:
    May 25, 2017
    Posts:
    487
    Awesome! Above and beyond. Thanks Tony, works like a charm. The EndOfFrame was the trick. Can you clue me in on something.
    Why would you call "yield return null" then "yield return new WaitForEndOfFrame()" right after?
     
  14. evanvi1997

    evanvi1997

    Joined:
    Dec 3, 2017
    Posts:
    5
    Thanks for the answer! I will try to find a solution ASAP!:):cool:
     
  15. philc_uk

    philc_uk

    Joined:
    Jun 17, 2015
    Posts:
    90
    When switched to 3rd person, and looking up in the sky while holding a rifle.. the character does not point up, he still kind of looks forwards and leans a bit, but firing does shoot in the right direction. Anybody got an approach to animate the character so they lean up to follow the mouse?

    Thanks
     
  16. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,694
    The first line (yield return null) waits for one full frame. This is the frame that RFPSP's scripts run their Start() methods to initialize things. The second line (yield return new WaitForEndOfFrame()) waits for the the next frame to finish, which is the frame in which the Save System applies the saved game data. We wait for the end of this frame to allow ApplyData to run first.
     
    jnbbender likes this.
  17. petercoleman

    petercoleman

    Joined:
    Feb 21, 2016
    Posts:
    477
    Hi TonyLi,

    Thanks for the reply...

    "hide your original NPC GameObject where the player can't get to it."

    Yes this is what i have done in the past but wanted to have a better solution :) As to using a prefab (Individual specific) I simply did not want to create a new prefab for every individual Character Spawner but I guess It will work and is the best method available.

    Thanks again

    Peter
     
  18. petercoleman

    petercoleman

    Joined:
    Feb 21, 2016
    Posts:
    477
    I have another request for help if anyone can please....

    Its platform related...

    I have some moving entities that the player enters and takes a ride on...e,g. Train, dropship. As far as it goes they work OK but I would like to improve upon them...

    My only issue is as is well known the player in my case is carried by the "Mover" but cant move around as the relative speeds of player are different. Well I can move around but at a different rate speed ratio and would like to be able to walk around inside moving objects as one normally does....

    I have searched around the web and tried some script options found and also used some scripts from assets I have but all have some other issues or other and I might as well stick to what I have which does work after a fashion as said...

    I will continue to search around but thought perhaps someone else may have done this (Player successfully walking around and carried on/inside objects/platforms in a realistic fashion). I actually do have another asset where this works fine but its script is too complex for me to transfer to my own items...as I am not a scripting expert...

    I need something relatively simple though I know its not so simple to do. I have everything working - player get in object object-moves player to target location following complex paths- Player get out of object and all that works fine so just want to improve the player movement inside an object by relating the player movement and object (Platform) position and speeds to one another so the player can walk on the platform when its moving...

    I have also tried parenting the Player to the Platform and various settings for everything but not cracked it yet - :)

    Thanks

    Petetr
     
  19. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,694
    @petercoleman - A common trick is to make the train stationary, and move the world around it. This avoids a lot of physics issues with the player. But it requires you to design your scene to work like this.
     
  20. jnbbender

    jnbbender

    Joined:
    May 25, 2017
    Posts:
    487
    Well a BIG thanks to RFPS and a very BIG thanks to everyone here for helping me release my first game on Unity! Please give it a shot. The menus still get a little jacked up but I'm working on it and don't forget to hit 'F1', I've added some things. Enjoy FACTIONS.
    https://jivtrky.itch.io/factions
     
    TonyLi likes this.
  21. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,694
    Congratulations on your release!
     
    jnbbender likes this.
  22. jons190

    jons190

    Joined:
    Sep 13, 2016
    Posts:
    260
    REALISTICFPS, REWIRED, UNITY MOBILE CONTROL ISSUE on ANDROID

    Hi everyone I just stumbled into an odd error that I hope someone can point me in the right direction to fix.

    config
    Unity 5.4 -REwired 1.1.5- RFPS 1.24 and pixel crusher interrogation script.
    Build for android 5.xxx and Gear VR. Bluetooth wireless gamepad support.


    First, everything was working great. Full integration with RFPS and rewired, got everything optimized, it all runs great and fine and has for months. (only had one small issue where occasionally the controller/rewired would randomly fire off a button repeatedly like 25 times in a row, but thought it was an actual hardware problem with the steelseries HID controller and low batteries and was relatively minor bug)

    Then a few days ago I imported the unity assets package "VR samples" into my project, as I wanted to see the code sample for how to resize the VR image buffer lower to gain a performance edge on the android device (which is a HUGE performance gainer on android BTW....)

    but the asset seemed to load up the "Unity mobile control" editor option as well and had automatically turned them on. and this has seriously messed up my rewired/unity integration /wireless gamecontroller/android setup and I have been trying solutions all day to get a fix with no resolution.

    I disabled mobile input in the editor

    I have deleted all the VR samples and standard assets folders in my project. (and thus removing the mobile interface control option from the Unity editor menu bar entirely)

    Rebooted ....Twice (because...well... you know...I am deving on a windows dev machine...)

    I have reinstalled rewired (not deleted and reinstalled, just reinstalled from the rewired window in the editor)

    Nothing fixes the issue. From what I can tell my keyboard/ rewired actions all map to the bluetooth controller fine, but the movement and look axises are messed up and will not work /move the RFPS prefab when I built to the android phone and do a live test with the controller.

    My rewired mouse and keyboard mapping work just fine in the editor however.

    So I know that the RFPS adds some control mappings somewhere within the project setting on first install, as well as rewired also seems to do that, and I suspect that when the mobile controls from the unity standard asset got installed it rewrote some info over these settings, (maybe specifically the movement and look axis settings) but I have no idea where this this info is stored within the overall project.

    I'm hoping I can find this config file and fix it , or over write it from a backup I have.

    or

    unistall RFPS and rewired and then load them fresh (not sure that will actually fix the problem, in the case of a lingering conf file or XML or datafile) and I've heavily modified and optimized the RFPS prefab and am not looking to duplicate that work with a freash version if I don't have too, but so be it if I have too....

    Anyway, anyones thoughts on this issue would be greatly appreciated and happy holidays!


    and congrats to jnnbender on the game release!
     
    Last edited: Dec 28, 2017
  23. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,694
    @jons190 - Your best bet is to revert to a previous version of your project before you imported VR Samples. (If you're not using a version control system, write "I will learn how to set up version control ASAP" on a post-it note and stick it on your monitor. ;))

    VR Samples is a Complete Project asset. This means it overwrites your ProjectSettings, which includes your input definitions, tags, layers, etc. The cleanest way to undo the damage it did is to revert.

    If you can't revert to a previous version, try these steps:
    1. Make a backup of your project as-is. You only need to copy/zip up Assets and ProjectSettings. Unity will recreate the other folders automatically.
    2. Import RFPS with these settings: deselect everything, and then select only the ProjectSettings. Then import.
    3. Select menu item Window > Rewired > Setup > Run Installer.
    4. Look over all the inspectors in Edit > Project Settings > ....
     
  24. jons190

    jons190

    Joined:
    Sep 13, 2016
    Posts:
    260
    Hahaha Tony li I have actually learned this VERY IMPORTANT LESSON about backups from the last three times I have pulled this type of blunder.... and I am , at this moment, pulling up and testing my last backup. It's unfortunately from about ten days ago, so there is a bunch of optimization work that I powered through that will have been lost (note to self, learned new lesson today on keeping a dev/change log so that the list of things changed int he past is not lost when something like this happens in the future) and I was hoping for a quick fix, but alas... there is rarely , it seems , such a thing...



    Also, I am currently just doing a simple Father /son/grandfather type of backup, where I just grab an entire build of my entire unity project and move it off to a backup drive once a week. I suspect I may need to start version control in earnest now with production code and "signed builds for oculus store check ins and all that ..) . Any good simple and lightweight systems for win and a one man dev ,shop preferably a local system, you would recommend I look at? I did microsoft VSS for years, but am loathed to set that system up. Doesn't unity integrate with something natively?


    Edit Backup worked fine, but now I am worried I am out of synch with my android keystore (a bit of a black box for me) and I hope I can sign my backupbuild with my keystore I used to check into the oculus store. (wheeeeee....... alwalys learning something new around here....)
     
  25. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,694
    Unity has a step-by-step tutorial, Creating Your First Source Control Repository, that uses Bitbucket, Git, and Sourcetree. You can ignore the Cloud Build stuff at the end of the tutorial, unless you want to use Cloud Build. Make sure to set your repository private so the whole Internet can't download it. The nice thing about version control is that you can commit updates frequently, and they only capture the changes so they're small and fast to make. If you commit every day or every few hours even, it's much easier to go back to previous versions without losing much work. You can also browse through each commit to see exactly what changed.
     
  26. jons190

    jons190

    Joined:
    Sep 13, 2016
    Posts:
    260

    excellent. thanks much. Tomorrow i am setting this up! say what do you know about the android keystore file process? Does it take a hash of the project at anytime? or is it just a simple encrypt PGP key ytype thing that invokes at signing? I.E: Can i simply pull over the keystore file from my projects production build (that just got corrupt) and install/move it into my backup project file and use that file to sign my backup project from 10 days ago?


    If not, it's actually not that big of deal since I don't go live till mid month on t\he oculus store and can easily just build a new story entry with a new keystore file in my backup project. but would like to know for future reference.
     
  27. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,694
    @jons190 - Sorry, I don't remember. Maybe someone else does?
     
  28. evanvi1997

    evanvi1997

    Joined:
    Dec 3, 2017
    Posts:
    5
    Hi all,
    After I purchased the RFPS and imported it into unity I noticed that I started having problems with particles. I have uploaded a video with a link to it in this post so please if you can kindly give it a look and please help me if possible. The first part of the video shows the unity particle pack example scene before importing RFPS and then after import it and the problems that start occurring. Thank you.:) (btw I had muse playing in the background so lower your headphones or speakers:p) LINK:https://ufile.io/bvfxl
     
  29. jons190

    jons190

    Joined:
    Sep 13, 2016
    Posts:
    260
    Hey Tony Li, Just a quick update for anyone who may face this issue in the future. Long story short, I moved my production keystore file over to the backup folder from the production folder where I was "hosting" the unity project files and signed a build, built using the backup project and it all looked like it signed a.o.k (won't really know till I upload tot he oculus store)

    I do not think the android studio keystore signing process generates a hash on the code it's self, maybe a hash from the computer config, but I suspect its is just a PGP public/private type mechanism and that keystore file could be moved from machine to machine and project to project.



    Now, onward to figure out how to do a startup gamepad detection script. (its a requirement for check in t othe store, yet there doesn't seem to be one example script anywhere on the web! zoiks!)
     
  30. jons190

    jons190

    Joined:
    Sep 13, 2016
    Posts:
    260
    Hey what version of uni
    tHey there. What versions of Unity and RFPS are you using?
     
  31. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,694
    Right. I'm pretty sure it's an SHA hash, which should be independent from your code and your machine.

    Try this code by robpuk38. It uses Input.GetJoystickNames().
     
  32. jons190

    jons190

    Joined:
    Sep 13, 2016
    Posts:
    260
    Ya th
    This is is the one I have been working with but not getting it to work. (I am finding I am a terrible programmer...)

    I am using rewired as the controller interface, and then using the "dual analog gamepad" definition within rewired to handle the controller (seems to catch about 80% of the controllers out there) so I don't have to use specific controller names or rewired controller definitions.

    Then the functionality is that this script runs on startup (when loading the first "splash screen" of the game.) If a controller is connected, then is just passes through unnoticed to the player to the second scene, but if not, then loops out to a side scene that says"no controller connected, please pair one with the device and try again."

    This only has to happen once at the game start up. but I can't get any of it to work.

    I have stripped out the xbox / ps4 specific code from this example code to make it more generic so that if ANY controller is present, then pass through.

    Then I wanted to setup a textGUI object within a secondary scene and use that to display the warning text about NOT having a controller, using some kind of If/then loop, but have now decided that a simple "print to screen" is all I really need instead of a fancy GUI object within it's own scene, but I've messed up that portion of the code up as well (not sure to use print statement, or debug.display call ect as not sure what mechanism displays text on the android device vers the unity console.)...


    Anyway, after gutting the RFPS and modding to all high heaven to get it to run on mobile at 60FPS I find it odd that this little (what I think should be a fairly straight forward 30 minute to author) script has been tripping me up for weeks and is the last little piece I need to fix for release.

    I think after I get this project done and out the door, I may do some "intro to coding" type classes for a few weeks as programming has definitely been identified as the week link in my game development process.... but on the flip side, I have become the frigged god of general optimization techniques.....


    How much would you charge me to bang out a script like that? ;-) ...said only half joking....



    Also on a side note. Do you know if Sphere and capsule colliders resolve faster the box collider for physics? Of course primitive colliders are much fast then mesh colliders, but I have read conflicting reports on just what primitive colliders are the fastest. Some say box colliders, some shay sphere colliders are the fastest.
     
  33. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,694
    @jons190 - Try this:
    Code (csharp):
    1. using UnityEngine;
    2. using UnityEngine.SceneManagement;
    3. using System.Collections;
    4.  
    5. public class RequireJoystick : MonoBehaviour
    6. {
    7.  
    8.     public GameObject connectJoystickMessage;
    9.     public string continueToScene;
    10.  
    11.     private IEnumerator Start()
    12.     {
    13.         while (Input.GetJoystickNames().Length == 0)
    14.         {
    15.             connectJoystickMessage.SetActive(true);
    16.             yield return new WaitForSeconds(2);
    17.         }
    18.         connectJoystickMessage.SetActive(false);
    19.         SceneManager.LoadScene(continueToScene);
    20.     }
    21. }
    Assign a GameObject, such as a Canvas with a message, to Connect Joystick Message.

    Set Continue To Scene to the name of a scene that should load as soon as a joystick is detected.

    It checks once every 2 seconds. You can speed up the frequency by changing WaitForSeconds(2).

    Regarding box vs. sphere colliders, I haven't dug into the source code, but I'm sure the difference is negligible. There are almost always much bigger performance factors than that.
     
  34. jons190

    jons190

    Joined:
    Sep 13, 2016
    Posts:
    260




    Ok I have this muddled together in my project, and think I follow it... (you threw me when you added the "while" statement as I am only figuring out if/thens ;-) Anyway I have a question.


    If the joystick is NOT DETECTED, is it a simple as moding the code to add a second public string and then adding/calling that string with scenemanager in the first routine?


    Code (csharp):
    1. using UnityEngine;
    2. using UnityEngine.SceneManagement;
    3. using System.Collections;
    4.  
    5. public class RequireJoystick : MonoBehaviour
    6. {
    7.  
    8.     public GameObject connectJoystickMessage;
    9.     public string continueToScene;
    10. //added second public class called continueToexitScene;
    11.     public string continueToexitScene;
    12.  
    13.     private IEnumerator Start()
    14.     {
    15.         while (Input.GetJoystickNames().Length == 0)
    16.         {
    17.             connectJoystickMessage.SetActive(true);
    18.             yield return new WaitForSeconds(2);
    19. //  Added a load new scene  if joystick is NOT detected....To load message/screen that states this and closes app in a graceful way
    20.             SceneManager.LoadScene(continueToexitScene);
    21.         }
    22.         connectJoystickMessage.SetActive(false);
    23.         SceneManager.LoadScene(continueToScene);
    24.     }
    25. }
     
    Last edited: Dec 31, 2017
  35. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,694
    The "while" statement tells the code to keep looping while a condition is true -- in this case, while there's no joystick. In other words, the script keeps waiting until a joystick is connected. I thought that's what you were looking for, but it seems that you just want to load a new scene either way: one scene if a joystick is connected, another if a joystick is not connected.

    It's simpler than that. Try this:
    Code (csharp):
    1. using UnityEngine;
    2. using UnityEngine.SceneManagement;
    3.  
    4. public class RequireJoystick : MonoBehaviour
    5. {
    6.  
    7.     public string gameScene;
    8.     public string noJoystickScene;
    9.  
    10.     private void Start()
    11.     {
    12.         // Does the list of joysticks have anything in it?
    13.         bool isJoystickPresent = (Input.GetJoystickNames().Length > 0);
    14.  
    15.         if (isJoystickPresent)
    16.         {
    17.             // If we have a joystick, load the game scene:
    18.             SceneManager.LoadScene(gameScene);
    19.         }
    20.         else
    21.         {
    22.             // If we do NOT have a joystick, load the "no joystick" scene:
    23.             SceneManager.LoadScene(noJoystickScene);
    24.         }
    25.     }
    26. }
    Side note: You've probably already noticed this, but the Unity editor caches the joystick list. If you start Unity with no joysticks connected, Input.GetJoystickNames() will return an empty list. If you then connect a joystick, it will return a list with a joystick name. But, then if you disconnect the joystick, Input.GetJoystickNames() will continue to return the name of the (disconnected) joystick, even though it's disconnected. The quickest way to get an accurate list in this case is to quit and restart Unity.
     
  36. GhereGames

    GhereGames

    Joined:
    Mar 24, 2015
    Posts:
    23
    When integrating RFPS with Dialogue system, it appears that any quest states in Dialogue System are not reset. Is there a way to do this automatically or will I need to reset their states when the player presses the restart button?

    I'm finally getting the skills needed to integrate all of these packages, and must say they are very powerful.

    Thanks!
     
  37. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,694
    Hi @GBCoder - You'll need to tell the Dialogue System to reset its state. Here are three ways to do it: (Choose whichever is convenient.)

    1. Assuming your Dialogue Manager has a Level Manager component, configure your restart button to call the LevelManager.RestartGame method. This will reset the Dialogue System's state and load the scene named in the Level Manager's Default Starting Level field.

    2. Or, use the PlayMaker (or other supported visual scripting system) Reset Dialogue Database action.

    3. Or, call DialogueManager.ResetDatabase() in a script.
     
  38. GhereGames

    GhereGames

    Joined:
    Mar 24, 2015
    Posts:
    23
    #3 did the trick. I'm only using one level, therefore I'm not using a LevelManager.
    Thank you for the quick information and for the great Asset.
     
  39. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,694
    Glad to help, and thanks!
     
  40. jons190

    jons190

    Joined:
    Sep 13, 2016
    Posts:
    260
    Isn't it amazing whats packed away in these assests. Once you start learning what they do, then get a taste of C# and realize you can mod just about anything... Well.... the possibilities are endless.... Happy new year!
     
    TonyLi likes this.
  41. GhereGames

    GhereGames

    Joined:
    Mar 24, 2015
    Posts:
    23
    I do have another question:

    Maybe someone can lead me in a direction. I have NPCs (Zombies) that are roaming around. They are in the NPCRegistry for rFPS. Ideally, it would be nice to save all of their states via Dialogue System Save and restore them upon a Load. Is there a way built into RFPS and Dialogue System to simplify this, or should I create an object that handles storing the state needed for the NPCs to be restored to the world and the NPC Registry?

    I don't want people to get swarmed and then save, restart, load and be free and clear.

    Thanks!
     
    Last edited: Jan 2, 2018
  42. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,694
    Hi GBCoder - Sorry, the Dialogue System's save subsystem doesn't cover the state of the NPCRegistry and spawned NPCs. If you're handy with scripting, you could make a copy of Dialogue System / Scripts / Templates / PersistentDataTemplate.cs and customize it to make a persistent data component that saves and loads this info. I'm afraid I haven't looked into it saving NPCRegistry data. I don't know if RFPS provides an easy way to do it.
     
  43. GhereGames

    GhereGames

    Joined:
    Mar 24, 2015
    Posts:
    23
    Thanks. I'll look into it. I used a modified PersistentDataTemplate to create a script to save the data from some objects I created. I'll give it a shot and if I get something that works well, I'll post it here.
     
  44. evanvi1997

    evanvi1997

    Joined:
    Dec 3, 2017
    Posts:
    5
    Hi there,
    I am currently using RFPS 1.44 and Unity 2017.3
     
  45. jons190

    jons190

    Joined:
    Sep 13, 2016
    Posts:
    260
    HEy Tony, Thanks for this, I'm going to give it a run tonight. On a side note, even though it seems like a simple script, I know there are lots of folks looking for this exact thing. It is a requirement for DaydreamVR, Oculus GO and GearVR store inclusion. You should polish it up and put it on the asset store for a few bucks.... Anyway, thanks much man and many happy new years!
     
  46. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,694
    Let's call that code public domain. If you get it working in your project, consider sharing it in a thread in the Scripting section. Good luck, and happy new year!
     
  47. guavaman

    guavaman

    Joined:
    Nov 20, 2009
    Posts:
    5,624
    If all you're trying to do is see if any controllers are connected to the system:

    Code (csharp):
    1. if(ReInput.controllers.joystickCount > 0) {
    2.     // do something
    3. }
    If you want to know whether your Player 0 has a controller assigned:
    Code (csharp):
    1. if(ReInput.players.GetPlayer(0).controllers.joystickCount > 0) {
    2.  // do something
    3. }
    Be sure you are not destroying the Rewired Input Manager and have "Don't Destroy on Load" checked in its inspector or you will have problems.
     
  48. jons190

    jons190

    Joined:
    Sep 13, 2016
    Posts:
    260
    Alright, Now for something slightly different.

    I'm on unity 5.4 and RFPS 1.24 and frankly, It's rock solid. (doing VR dev with it) But. It's time for an upgrade now that I am inbetewwen projects .... How is the new 2017 unity and RFPS 1.44(?) working for everybody? Any major glitches? Should I go to 5.6 and call it good? How easy i iti to swap out enemies and weapons in the newst versions?

    Any feedback would be greatly appreciated.
     
  49. MaliceA4Thought

    MaliceA4Thought

    Joined:
    Feb 25, 2011
    Posts:
    406
    Can only help you a little here :)

    I'm using RFPS 1.44 and Unity 2017.1.2f1 and have no issues at this stage. I have swapped the player character with a UMA one as per the video a few posts ago.

    As to enemies and weapons.. I am not using RFPS enemies, I am using Emerald 2.0.1 for the AI and enemies with characters from protofactor and it's good at the moment and working fine.

    Other packages I have working nicely in this are Gaia, CTS, Vegetation Studio, Enviro and HUD Navigation System. I have installed, but not yet started using, Dialogue Manager and Quest Machine but they are in there and no console errors and ready to use.

    My only weapons so far in the game are knife, sword, sword/shield and bow and those have had model changes and been re-jigged to work with the UMA character and are OK.

    One of the big changes was the move to mechanim for everything and that has changed the workflow with regards to animation, NPC and weapon replacement a fair amount, so there is relearning, but the combo of 1.44 and 2017.1.2f1 seems stable.

    Hope that helps some.

    M
     
    jons190 and TonyLi like this.
  50. MaliceA4Thought

    MaliceA4Thought

    Joined:
    Feb 25, 2011
    Posts:
    406
    Thought I would add a screenshot showing the things mentioned in my above post.

    UMA character + Arteria3d Templar Knight clothing with ingame Katana.
    Environment.. Gaia + CTS + Enviro + Vegetation Studio
    HUD Navigation System
    2km x 2km terrain

    PC specs i5-4460 @ 3.2 GHz with 16 gig Ram and GTX970 at 1920 x 1080 on Ultra settings with 125FPS in this screenshot.

    @TheMessyCoder thanks for the setup video :D

    rfpsuma.jpg

    M
     
    Last edited: Jan 5, 2018
    ronaldomoon and kenamis like this.