Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

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,670
    Is it a scale issue on the object? Can you set the parent's scale to (1,1,1)?
     
  2. Defcon44

    Defcon44

    Joined:
    Aug 19, 2013
    Posts:
    400
    Thanks for reply.

    I make change the size to 1,1,1 and that get this :

     
  3. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,670
    Is that closer to what you're looking for? If the vehicle is too big, maybe you can change the scale when you import the model (on the importer's Rig tab).
     
  4. Defcon44

    Defcon44

    Joined:
    Aug 19, 2013
    Posts:
    400
    Then the vehicule are the good size (like player) y a have the big impact on the door

    But then i change size of door to 1,1,1 (lire picture) the impact is good for this size :s
     
  5. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,670
    I think RFPS's impacts work best when the GameObjects' scales are (1,1,1). If you can set the scale on the Rig tab when importing the model, that will be the best solution.
     
  6. Defcon44

    Defcon44

    Joined:
    Aug 19, 2013
    Posts:
    400
    What do you mean by "If you can set the scale on the Rig tab when importing the model" ?
     
  7. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,670
    Sorry, I meant the Model tab. Set the Scale Factor.
     
  8. Defcon44

    Defcon44

    Joined:
    Aug 19, 2013
    Posts:
    400
    Ah ok, thanks for Trick ;)

    But i have change scale of child to 1,1,1 and after that i have change the scale of gameobject and that works :)
     
    TonyLi likes this.
  9. TopThreat

    TopThreat

    Joined:
    Aug 7, 2012
    Posts:
    136
    Hello! I have made some changes to visible body to show a body of my choosing instead of the default and now my player is no longer affected by damage from NPC enemies. I can still be harmed by damage areas or an explosion, and I can still harm NPC's. I have looked at the different settings between the default prefab which is still able to be damaged in the demo scene but could not find what I screwed up :(

    The NPC's will find and chase the player, they will do the attack animation or shoot at the player but nothing happens... no damage...

    Which settings or variables do I need to be aware of to ensure that enemy NPC's can actually harm my player?

    Thank you so much in advance for any help you can provide with this. I have been poking at it for several hours and can't find whatever it is thats causing this issue.
     
  10. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,670
    Do the layers match the original prefab exactly? RFPS works on a layer basis. If the layers aren't right, it won't even get to the script part.
     
  11. TopThreat

    TopThreat

    Joined:
    Aug 7, 2012
    Posts:
    136
    Everything was the same except for the scale. Changed the scale of the prefab to 1 from .8 and now I can be damaged. So strange... Thank you for the advice, it helped me refocus on which items were different.
     
  12. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,670
    Wow, I wouldn't have expected scale to affect it. Glad it's working though!
     
    Defcon44 likes this.
  13. wheelbarrow

    wheelbarrow

    Joined:
    Sep 12, 2011
    Posts:
    177
    A quick question: I'm still using Unity4.6 for my current project, so I'm using an earlier version of RFPS ( the last one before it was upgraded to Unity 5), but I would think the question is still relevant. I have put some ammo pickups inside a chest for the player to find, and they are childed to the chest, but when I open the chest and pick up the ammo, it doesn't register in the ammo count for some reason. Nothing on the ammo was changed except the scale to make it fit inside the chest, so now I'm wondering if this is similar to the above problem LeeAllen was having, or can you think of another reason it wouldn't register? It picks up as normal.
    Cheers.
    Edit: Well we can rule out the scale, I just tried it without scaling the ammo, and though it picks up as normal, it still doesn't register in the ammo count. Bugger. Any help is appreciated.
     
    Last edited: Sep 14, 2015
  14. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,670
    I just tested this in RFPS 1.21 in Unity 4.6, and it works. Here are some things to check:
    • Is the correct Weapon Number set on the Ammo Pickup script?
    • Is Ammo To Add the correct amount?
    • Tag: Usable
    • Layer: Ragdolls/Pickups
    • Rigidbody and non-trigger Box Collider?
    I'm guessing those last few are fine, since you said the pickup gives the appearance of working but doesn't actually increment the ammo. Hopefully it's something simple like the wrong Weapon Number.
     
    Defcon44 likes this.
  15. wheelbarrow

    wheelbarrow

    Joined:
    Sep 12, 2011
    Posts:
    177
    You were right Tony, the weapon number was wrong. Many thanks for your assistance :)
     
  16. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,670
    Happy to help!
     
  17. llJIMBOBll

    llJIMBOBll

    Joined:
    Aug 23, 2014
    Posts:
    578
    Hi im having a simular problem the ai wont attack me. They chase me and maybe once they will attack and does do damage to me.
    It works ok in demo scene so i know scripts are ok. Im using wave spawner and doees same if i drag a prefab into scene. Thanx if anyone can help.
     
  18. Baraff

    Baraff

    Joined:
    Aug 16, 2014
    Posts:
    255
    I am having a strange issue currently:

    1. If npc1 is spawned from a Spawner under control of WaveManager, it works fine. Stops at correct distance and shoots player.
    2. If npc1 is dragged into the scene is works fine. Stops at correct distance and shoots player.
    3. If I manually call spawn from other code npc1 will most of the time (95%) keeps running until is has run into the player or beyond before it will start shooting.
    4. If npc1 is spawned using method 3, it will work ok if the player moves, but not if the player not move. Rotation without moving the player does not work, the player has to actually move a
    To make this even stranger it seems that it happens to 2 types of NPCs while another 2 with identical settings work fine under the same code scenarios.

    Besides this, there seems to be a possibility for any NPC to get into a game of leap from with other NPCs, such that they will keep moving past other NPCs over and over until they are on top of the player and pushing the player along.

    Is there a way to put a hard stop on this kind of behavior as I can't see a good reason for it.

    BTW, just using Navmesh in case that matters.
     
  19. llJIMBOBll

    llJIMBOBll

    Joined:
    Aug 23, 2014
    Posts:
    578
    Hey so i dragged in a new player, into a new scene and a zombie and it attacked me, so i deleted old characher i had, and made a new player, and after the zombie didn't attack again.
    so i went thru all settings to see what it was, and it turn out it was because i have allow leaning turned off ??? wut xD
    but now the zombie attacks me again :D just thought i'd say maybe can help

    EDIT! Also i found out how to fix it, if you want to disable lean function, disable in inspector and also disable it on the player under camera too... that way the ai will attack you
     
    Last edited: Sep 16, 2015
  20. Deleted User

    Deleted User

    Guest

    Hi, sorry to hear you've encountered an issue with the NPCs. First of all, are there any errors in the console window, or are the NPCs just not tracking the player as expected? Also, are either of you using the default NPCs, or new ones that you've created/duplicated? If you're using custom NPCs, one thing you might want to check is that the NPCs' Eye Height value of their AI.cs component is high enough so they are tracking the player from the height of their eyes. Some Character models have their origins near their feet, and if the Eye Height offset value is zero, they won't be able to see their targets consistently from ground level. You can view the NPC eye height positions by checking the Draw Debug Gizmos box at the bottom of the AI.cs component for visual tweaking of the eye heights. Hope that might give you some ideas.



    Apologies for my absence from the forums lately. It's been a busy few months, but development has continued. There's currently a backlog of support requests that we're working to get caught up on. Very sorry about this and thanks for your patience.

    Just wanted to cover some of the main questions that I've seen posted. First of all, the flickering shadows and/or jittering models is due to the common computer graphics issue of z-fighting. There's a limited amount of precision for the z-buffer, which is tied to the distance of the near and far clip planes of the camera. Since the single camera setup uses a closer near-clip plane to allow the weapon models to be placed closer to the camera, this can cause some z-fighting in larger scenes. The 2 camera setup minimizes this issue, but the trade off is that there are no shadows from world geometry casted on the weapons and, so far, the new deadzone aiming system does not work correctly yet, due to the upscaled weapon models.

    The main things you can do to minimize flickering/jittering with the one camera setup, is to arrange your scene like in the terrain test demo, with the center of your terrain/level located at the scene origin (coordinates 0,0,0), since the floating point precision decreases further away from the origin. The borders of your level should extend to positive and negative amounts on each side, such as 500 to -500 units, to maximize use of the higher-precision area of the scene. Secondly, you can increase the camera near clip plane to .03 from the default .01. 0.03 will become the default near clip plane value in the next version. These values are still pretty low, but it's a tradeoff to allow the weapons to be closer to the camera and fit within the player capsule collider. If you find that the weapons occasionally are clipped by the near plane, you can decrease the Sway Amount value in the GunSway.cs component of the FPS Player object to 0.5, to reduce the weapon sway while rotating the main view. These changes should help with the flickering/jittering issue.


    As for ladders not working, you might need to check that the friction value/combine mode of the physics material on the ladder is set to a lower value. Unity 5 introduced changes to the physics system which requires the physics materials to be tweaked in some cases.


    A Mecanim player model is definitely on the list. Can't say for sure if it will be part of the upcoming update, or afterwards, but it is an important feature we're working on.


    Concerning the performance of the AI script, in previous versions, the CanSeeTarget coroutine of AI.cs ran every frame. This was an oversight on our part, which could lead to slower performance with larger amounts of NPCs. In version 1.22, CanSeeTarget, which uses raycasts/spherecasts to calculate target visibility, should only be running about twice a second. At rates slower than that, there is a noticeable delay to NPC reaction time, which breaks immersion a bit. We did some tests with the NPC spawners, and only started to notice a slowdown in version 1.22 when there were around 40 NPCs active in one scene, though this might have been due to the speed of the testing machine or simplicity of the demo scene. Performance could be improved by making NPC's "sleep" if out of range of the player. We plan to continually optimize the AI code and add a few more features, such as following and travel-to-destination behaviors for quest scripting and allies. Please let us know about your experiences using the default AI, as it helps us improve the asset.


    About the next update, so far we've implemented a few features since 1.22:
    • Footstep sounds that change based on terrain texture (grass, dirt, rock)
    • Object pooling system for decals, ejected shells, and temporary audio sources
    • Deadzone aiming with customizable deadzone ranges to allow independent weapon movement from the camera

    Object pooling is a technique that activates/deactivates existing objects from an object pool instead of instantiating/destroying new objects at runtime. This is done for performance reasons and is better for the garbage collector, since thousands of objects could be instantiated in a scene vs just a hundred or so that are re-used. The object pooling system is written as simple as possible, using integer values to reference objects in the object pool, and should be compatible with networking packages.

    The deadzone aiming feature is entirely optional, but allows the player to move their weapon inside the camera view without rotating the camera, until the weapon enters the edges of the screen, then the camera rotates as normal. The first deadzone aiming mode is like the one in the ARMA games, with the weapon moving independently when aiming from the hip, but moving with the camera when zoomed. The second deadzone aiming mode is similar to games like Goldeneye or Perfect Dark, where the player has no crosshair and rotates the camera with the weapon when aiming from the hip, but when zoomed, the crosshair appears and the weapon moves independently of the camera angles with increased shot accuracy.

    The pivot point for weapon rotation in deadzone aiming mode is also customizable from the inspector. Deadzone aiming will probably be customizable per weapon as well, so a handheld flashlight could be moved independently, with other weapons aiming differently, for example.

    In the web demo, you can press LEFT ALT to toggle between the ARMA style deadzone aiming and COD style aiming. The Y KEY will toggle the Goldeneye/Perfect Dark style deadzone aiming. If you have any questions or ideas about these new features, please let us know.


    We've also had requests for a version of the Realistic FPS Prefab that is still compatible with Unity 4 and we're looking into the best way to distribute it (possibly though the Asset store with a U4 version and U5 version available as a free upgrade with the advanced image effects and shaders).
     
    Last edited by a moderator: Sep 16, 2015
    QuadMan, Takahama, TonyLi and 2 others like this.
  21. Defcon44

    Defcon44

    Joined:
    Aug 19, 2013
    Posts:
    400
    Hi Azuline !

    Happy to see you back :)

    The new features is really good ! Good job !

    I want this new update queckly ^^
     
  22. Gua

    Gua

    Joined:
    Oct 29, 2012
    Posts:
    455
    Glad to hear that this feature will be implemented. UFPS implementation of that feature had a significant flaw.
    UFPS implementation didn't played any sounds for textures that were not in a pool. But I believe that the best approach to have, is to play default walking sounds when player walks on textures that are not specified in a texture pool, instead of not playing any walking sounds.

    p.s. One small suggestion. Give option not to show health level below 0.
     
    Last edited: Sep 16, 2015
  23. llJIMBOBll

    llJIMBOBll

    Joined:
    Aug 23, 2014
    Posts:
    578
    hi im trying to make a toggle button for a ui to turn godmode on and off, i made this function, it turns it on but it doesnt toggle off. how can i make it toggle? thanx
    Code (CSharp):
    1. public void godMode()
    2.     {
    3.         fpsPlayer.godMode = enabled ;
    4.     }
    xD i fix it, still learning
    Code (CSharp):
    1. public void godMode()
    2.     {
    3.         fpsPlayer.godMode = !fpsPlayer.godMode ;
    4.     }
     
    Last edited: Sep 16, 2015
  24. Baraff

    Baraff

    Joined:
    Aug 16, 2014
    Posts:
    255
    Thanks for the reply.

    Using custom models based on the example mechanim.
    I had already checked eye height with gizmos, and they seem ok... All set at 1.8.
    I will come back to this part later as these models may or may not be used I just found it odd that they worked differently depending on how they were spawned.

    Besides the above problem though there is still the issue that the NPCs will, if their view is blocked by other NPCs get into a type of leap frog where they all take turns in moving around the blocking NPCs until the player is overrun by NPCs pushing the player along. It would be better if it was possible to stop that behavior so they never came closer than a set value.

    Update: I have found a good enough work around to the pushing issue and it was dead simple. Updating here in case it helps others. Just add a Nav Mesh Obstacle to the FPS Player and set it to capsule with the Radius set to the distance that suits you. The NPC's will no longer push the player around, but will happily surround the player.
     
    Last edited: Sep 18, 2015
  25. llJIMBOBll

    llJIMBOBll

    Joined:
    Aug 23, 2014
    Posts:
    578
    hi i am stuck can someone help me with my code, i get a error saying "Object reference not set to an instance of an object"
    my code i have is for a UI button which i toggle on/off...
    Code (CSharp):
    1. public void GodMode()
    2.     {
    3.         fpsPlayer.godMode = !fpsPlayer.godMode ;
    4.     }
    5.  
    6. public void Crosshair()
    7.     {
    8.         fpsPlayer.crosshairEnabled =    !fpsPlayer.crosshairEnabled;
    9.     }
    also have one more question i bought dialogue today and implemented the save feature into my game, but im wondering how i would intergrate so it can save my score too... im using a simple score system someone posted on here thanx
    Scoremanager.score

    edit! i managed to save the score :D

    im using the wave manager, can i save with wave it is and the zombies which are alive?
     
    Last edited: Sep 18, 2015
  26. Takahama

    Takahama

    Joined:
    Feb 18, 2014
    Posts:
    169
    Yay! Still i want Follow Player checkbox for AI :p
    And a glitch report : Mine doesnt explode barrel, just make it fly ._.
     
  27. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,670
    Hi @llJIMBOBll - Make your fpsPlayer variable public. Then assign your player prefab's FPSPlayer component to it.

    Create a new script named PersistentScoreManager.cs containing this:
    Code (csharp):
    1. using UnityEngine;
    2. using PixelCrushers.DialogueSystem;
    3.  
    4. public class PersistentScoreManager : MonoBehaviour {
    5.  
    6.     public void OnRecordPersistentData() {
    7.         DialogueLua.SetVariable("Score", ScoreManager.score);
    8.     }
    9.  
    10.     public void OnApplyPersistentData() {
    11.         ScoreManager.score = DialogueLua.GetVariable("Score").AsInt;
    12.     }
    13. }
    Then add this script to your Dialogue Manager GameObject.
     
    llJIMBOBll likes this.
  28. llJIMBOBll

    llJIMBOBll

    Joined:
    Aug 23, 2014
    Posts:
    578
    Thanx alot for your help! :D
     
  29. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,670
    My pleasure! Thanks for using the Dialogue System!
     
    llJIMBOBll likes this.
  30. llJIMBOBll

    llJIMBOBll

    Joined:
    Aug 23, 2014
    Posts:
    578
    been meaning to get it for a while, i saw it on offer was too good to refuse xd :D Thanx again Your Amazing Help :D
     
    Ony likes this.
  31. Deppex

    Deppex

    Joined:
    May 31, 2015
    Posts:
    21
    Hello all

    I want to know if my player is on navmesh or not,
    or how know my AI is my player on navmesh or not.

    (for example)
    player.isOnNavMesh = true;
    player.isOnNavMesh = false;

    How do I do that;
     
  32. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,670
    You could use NavMesh.SamplePosition:
    Code (csharp):
    1. NavMeshHit hit;
    2. var isPlayerOnNavMesh = NavMesh.SamplePosition(player.transform.position, out hit, 1, NavMesh.AllAreas);
     
  33. Deppex

    Deppex

    Joined:
    May 31, 2015
    Posts:
    21
    Thanks TonyLi You're great

    I have another question.

    If an obstacle on the road condition
    my AI will not change direction
    AI runs or walking but does not move forward.

    I want that my AI when an obstacle changing direction.

    How do I do that.
     
  34. Baraff

    Baraff

    Joined:
    Aug 16, 2014
    Posts:
    255
    @Deppex If the obstacle on the road does not move you can set it as static in the inspector and rebake the navmesh.
    If the obstacle does move you can just add a Nav Mesh Obstacle to the obstacle on the road and the AI should navigate around it even if it moves. Be sure to set the Carve option in inspector for the Nav Mesh Obstacle component.


    I have a question that someone might know. I am spawning some non AI NPCs using the WaveManager. This is working until I kill one. No further non AI NPCs are spawned from that spawner. This is only a problem if I am also controlling the number of active NPCs from that spawner with the NPC Loads setting and the max is active when I kill one. If I don't use that they all spawn fine even if I kill some while the wave spawning is still underway.

    Anyone know where the code is that stops and starts the spawning when the active loads get maxed and then one dies?

    Hope that made sense.
     
  35. Deppex

    Deppex

    Joined:
    May 31, 2015
    Posts:
    21
    Thanks Baraff works well enough.
     
    Baraff likes this.
  36. Deppex

    Deppex

    Joined:
    May 31, 2015
    Posts:
    21
    I have a small problem with spawned NPC.

    Spawned NPC walking well all Waypoints
    but as NPC last waypoint has reached
    than he stays there will not walk.
    I want it just keeps walking.

    I've tried everything I know
    but not work.

    Resolved
    This is the solution.

    Code (CSharp):
    1. IEnumerator Patrol(){
    2.         while (true) {
    3.             if(curWayPoint && waypointGroup){//patrol if NPC has a current waypoint, otherwise stand watch
    4.                 Vector3 waypointPosition = curWayPoint.position;
    5.                 float waypointDist = Vector3.Distance(waypointPosition, myTransform.position);
    6.                 int waypointNumber = waypointGroup.wayPoints.IndexOf(curWayPoint);
    7.  
    8.                 //if NPC is close to a waypoint, pick the next one
    9.                 if((patrolOnce && waypointNumber == waypointGroup.wayPoints.Count - 1)){
    10.                     if(waypointDist < pickNextWaypointDistance){
    11.                         countBackwards = true;
    12.                         curWayPoint = PickNextWaypoint (curWayPoint, waypointNumber);
    13.                     }
    14.                
    15.                 }else{  
    16.                     if(waypointDist < pickNextWaypointDistance){
    17.                         if(waypointGroup.wayPoints.Count == 1){
    18.                             speedAmt = 0.0f;
    19.                             startPosition = waypointPosition;
    20.                             StartCoroutine(StandWatch());
    21.                             yield break;//cancel patrol if NPC has reached their only waypoint
    22.                         }
    23.                         curWayPoint = PickNextWaypoint (curWayPoint, waypointNumber);
    24.                         if(spawned && Vector3.Distance(waypointPosition, myTransform.position) < pickNextWaypointDistance){
    25.                             walkOnPatrol = true;//make spawned NPCs run to their first waypoint, but walk on the patrol
    26.                         }
    27.                     }
    28.                 }
     
    Last edited: Sep 23, 2015
  37. imaginationrabbit

    imaginationrabbit

    Joined:
    Sep 23, 2013
    Posts:
    349
    Just bought this asset- awesome work! I have one small question

    I'm using the FPS Main 1 Camera in my setup- I'm using Playmaker as I don't know how to code- What script/variable should I change on the player if I want them to freeze temporarily?

    I have a small cutscene that plays but I'll still using the FPS camera as the active camera for it- I just want to make it so the player can't move, shoot, look around, or jump and so the player animations don't play for a short period of time while the cutscene plays once its done it'll switch back to normal controls-

    I'm able to stop the camera from looking around by disabling the smooth mouse look script and I can get the player to stop by setting the walk and sprint speed to 0 but the player is still animating and able to fire- would appreciate any tips- thanks!

    Edit: I think I answered my own question by enabling/disabling the input control script :) Would that be the correct way to do what I want as it seems to work?
     
    Last edited: Sep 23, 2015
    Deleted User likes this.
  38. NeuroToxin-Studios

    NeuroToxin-Studios

    Joined:
    Dec 7, 2014
    Posts:
    68
    As long as this is before the scene really begins (Before the player has shot their weapon etc) then disabling the scripts should work fine, if the game will have started before the cutscene starts disabling and re-enabling the scripts could reset values such as ammo and health.
     
  39. llJIMBOBll

    llJIMBOBll

    Joined:
    Aug 23, 2014
    Posts:
    578
    Hi i'm wondering how easy it will be add a stamina bar? can anyone point me in the right direction thanx :)
     
  40. imaginationrabbit

    imaginationrabbit

    Joined:
    Sep 23, 2013
    Posts:
    349
    Thanks for the heads up! I'll watch out for that- If it does happen I guess I could store the var before switching the script off then set them back to what they were when I turn it back on.
     
    NeuroToxin-Studios likes this.
  41. llJIMBOBll

    llJIMBOBll

    Joined:
    Aug 23, 2014
    Posts:
    578
    Ok guys i started to make "Inventory Master - uGUI" www.assetstore.unity3d.com/en/#!/content/26310 work with RFPS, this is a real nice simple clean inventory system Its now FREE on asset store, i was one of the dudes who bought it before it went FREE.
    I got it so it will stop RFPS inputs when a inventory window is open, and i started to modify the "PlayerInventory" script, i've hit a wall tho so thought i'd share what i've done so far maybe you guys can help make it work.

    Attach these 2 scripts to FPS Player component

    This is to stop input!

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class jimsRFPSInvInput : MonoBehaviour {
    5.  
    6.     GameObject _inventory;
    7.     GameObject _tooltip;
    8.     GameObject _character;
    9.     GameObject _dropBox;
    10.     float verticalVelocity = 0;
    11.  
    12.     GameObject inventory;
    13.     GameObject craftSystem;
    14.     GameObject characterSystem;
    15.  
    16.     private FPSRigidBodyWalker FPSPlayer = null;
    17.     private SmoothMouseLook InputControl = null;
    18.  
    19.  
    20.     void Start()
    21.     {
    22.         FPSPlayer = GameObject.FindObjectOfType(typeof(FPSRigidBodyWalker)) as FPSRigidBodyWalker;
    23.         InputControl = GameObject.FindObjectOfType(typeof(SmoothMouseLook)) as SmoothMouseLook;
    24.            
    25.         if (GameObject.FindGameObjectWithTag("Player") != null)
    26.         {
    27.             PlayerInventory playerInv = GameObject.FindGameObjectWithTag("Player").GetComponent<PlayerInventory>();
    28.             if (playerInv.inventory != null)
    29.                 inventory = playerInv.inventory;
    30.             if (playerInv.craftSystem != null)
    31.                 craftSystem = playerInv.craftSystem;
    32.             if (playerInv.characterSystem != null)
    33.                 characterSystem = playerInv.characterSystem;
    34.         }
    35.     }
    36.  
    37.     void Update()
    38.     {  
    39.         if (!lockMovement())
    40.         {                  
    41.             Screen.lockCursor = true;
    42.             FPSPlayer.enabled = true;
    43.             InputControl.enabled = true;
    44.         }
    45.         else
    46.         {
    47.             Screen.lockCursor = false;
    48.             FPSPlayer.enabled = false;
    49.             InputControl.enabled = false;
    50.         }  
    51.     }
    52.  
    53.     bool lockMovement()
    54.     {
    55.         if (inventory != null && inventory.activeSelf)
    56.             return true;
    57.         else if (characterSystem != null && characterSystem.activeSelf)
    58.             return true;
    59.         else if (craftSystem != null && craftSystem.activeSelf)
    60.             return true;
    61.         else
    62.             return false;
    63.     }
    64. }
    Then replace this with original PlayerInventory script

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3. using UnityEngine.UI;
    4. using UnityEngine.EventSystems;
    5.  
    6. public class PlayerInventory : MonoBehaviour
    7. {
    8.     public GameObject inventory;
    9.     public GameObject characterSystem;
    10.     public GameObject craftSystem;
    11.     private Inventory craftSystemInventory;
    12.     private CraftSystem cS;
    13.     private Inventory mainInventory;
    14.     private Inventory characterSystemInventory;
    15.     private Tooltip toolTip;
    16.  
    17.     private InputManager inputManagerDatabase;
    18.     private FPSPlayer fpsPlayer;
    19.     private Transform myTransform;
    20.    
    21.     int normalSize = 3;
    22.  
    23.     public void OnEnable()
    24.     {
    25.         Inventory.ItemEquip += OnBackpack;
    26.         Inventory.UnEquipItem += UnEquipBackpack;
    27.  
    28.         Inventory.ItemEquip += OnGearItem;
    29.         Inventory.ItemConsumed += OnConsumeItem;
    30.         Inventory.UnEquipItem += OnUnEquipItem;
    31.  
    32.         Inventory.ItemEquip += EquipWeapon;
    33.         Inventory.UnEquipItem += UnEquipWeapon;
    34.     }
    35.  
    36.     public void OnDisable()
    37.     {
    38.         Inventory.ItemEquip -= OnBackpack;
    39.         Inventory.UnEquipItem -= UnEquipBackpack;
    40.  
    41.         Inventory.ItemEquip -= OnGearItem;
    42.         Inventory.ItemConsumed -= OnConsumeItem;
    43.         Inventory.UnEquipItem -= OnUnEquipItem;
    44.  
    45.         Inventory.UnEquipItem -= UnEquipWeapon;
    46.         Inventory.ItemEquip -= EquipWeapon;
    47.     }
    48.  
    49.     void EquipWeapon(Item item)
    50.     {
    51.         if (item.itemType == ItemType.Weapon)
    52.         {
    53.             //add the weapon if you unequip the weapon
    54.         }
    55.     }
    56.  
    57.     void UnEquipWeapon(Item item)
    58.     {
    59.         if (item.itemType == ItemType.Weapon)
    60.         {
    61.             //delete the weapon if you unequip the weapon
    62.         }
    63.     }
    64.  
    65.     void OnBackpack(Item item)
    66.     {
    67.         if (item.itemType == ItemType.Backpack)
    68.         {
    69.             for (int i = 0; i < item.itemAttributes.Count; i++)
    70.             {
    71.                 if (mainInventory == null)
    72.                     mainInventory = inventory.GetComponent<Inventory>();
    73.                 mainInventory.sortItems();
    74.                 if (item.itemAttributes[i].attributeName == "Slots")
    75.                     changeInventorySize(item.itemAttributes[i].attributeValue);
    76.             }
    77.         }
    78.     }
    79.  
    80.     void UnEquipBackpack(Item item)
    81.     {
    82.         if (item.itemType == ItemType.Backpack)
    83.             changeInventorySize(normalSize);
    84.     }
    85.  
    86.     void changeInventorySize(int size)
    87.     {
    88.         dropTheRestItems(size);
    89.  
    90.         if (mainInventory == null)
    91.             mainInventory = inventory.GetComponent<Inventory>();
    92.         if (size == 3)
    93.         {
    94.             mainInventory.width = 3;
    95.             mainInventory.height = 1;
    96.             mainInventory.updateSlotAmount();
    97.             mainInventory.adjustInventorySize();
    98.         }
    99.         if (size == 6)
    100.         {
    101.             mainInventory.width = 3;
    102.             mainInventory.height = 2;
    103.             mainInventory.updateSlotAmount();
    104.             mainInventory.adjustInventorySize();
    105.         }
    106.         else if (size == 12)
    107.         {
    108.             mainInventory.width = 4;
    109.             mainInventory.height = 3;
    110.             mainInventory.updateSlotAmount();
    111.             mainInventory.adjustInventorySize();
    112.         }
    113.         else if (size == 16)
    114.         {
    115.             mainInventory.width = 4;
    116.             mainInventory.height = 4;
    117.             mainInventory.updateSlotAmount();
    118.             mainInventory.adjustInventorySize();
    119.         }
    120.         else if (size == 24)
    121.         {
    122.             mainInventory.width = 6;
    123.             mainInventory.height = 4;
    124.             mainInventory.updateSlotAmount();
    125.             mainInventory.adjustInventorySize();
    126.         }
    127.     }
    128.  
    129.     void dropTheRestItems(int size)
    130.     {
    131.         if (size < mainInventory.ItemsInInventory.Count)
    132.         {
    133.             for (int i = size; i < mainInventory.ItemsInInventory.Count; i++)
    134.             {
    135.                 GameObject dropItem = (GameObject)Instantiate(mainInventory.ItemsInInventory[i].itemModel);
    136.                 dropItem.AddComponent<PickUpItem>();
    137.                 dropItem.GetComponent<PickUpItem>().item = mainInventory.ItemsInInventory[i];
    138.                 dropItem.transform.localPosition = GameObject.FindGameObjectWithTag("Player").transform.localPosition;
    139.             }
    140.         }
    141.     }
    142.  
    143.     void Start()
    144.     {
    145.         fpsPlayer = GetComponentInChildren<FPSPlayer>();
    146.  
    147.         if (inputManagerDatabase == null)
    148.             inputManagerDatabase = (InputManager)Resources.Load("InputManager");
    149.  
    150.         if (craftSystem != null)
    151.             cS = craftSystem.GetComponent<CraftSystem>();
    152.  
    153.         if (GameObject.FindGameObjectWithTag("Tooltip") != null)
    154.             toolTip = GameObject.FindGameObjectWithTag("Tooltip").GetComponent<Tooltip>();
    155.         if (inventory != null)
    156.             mainInventory = inventory.GetComponent<Inventory>();
    157.         if (characterSystem != null)
    158.             characterSystemInventory = characterSystem.GetComponent<Inventory>();
    159.         if (craftSystem != null)
    160.             craftSystemInventory = craftSystem.GetComponent<Inventory>();
    161.     }
    162.  
    163.     void UpdateHUDBar()
    164.     {
    165.         if (fpsPlayer.healthGuiObjInstance != null) {
    166.             foreach (var health in fpsPlayer.healthGuiObjInstance.GetComponentsInChildren<HealthText>()) {
    167.                 health.healthGui = Mathf.FloorToInt(fpsPlayer.hitPoints);
    168.             }
    169.         }
    170.         if (fpsPlayer.hungerGuiObjInstance != null) {
    171.             foreach (var hunger in fpsPlayer.hungerGuiObjInstance.GetComponentsInChildren<HungerText>()) {
    172.                 hunger.hungerGui = Mathf.FloorToInt(fpsPlayer.hungerPoints);
    173.             }
    174.         }
    175.         if (fpsPlayer.thirstGuiObjInstance != null) {
    176.             foreach (var thirst in fpsPlayer.thirstGuiObjInstance.GetComponentsInChildren<ThirstText>()) {
    177.                 thirst.thirstGui = Mathf.FloorToInt(fpsPlayer.thirstPoints);
    178.             }
    179.         }
    180.     }
    181.  
    182.  
    183.     public void OnConsumeItem(Item item)
    184.     {
    185.         for (int i = 0; i < item.itemAttributes.Count; i++)
    186.         {
    187.             if (item.itemAttributes[i].attributeName == "Health")
    188.             {
    189. //                if ((fpsPlayer.hitPoints + item.itemAttributes[i].attributeValue) > fpsPlayer.maximumHitPoints)
    190. //                    fpsPlayer.hitPoints = fpsPlayer.maximumHitPoints;
    191. //                else
    192. //                    fpsPlayer.hitPoints += item.itemAttributes[i].attributeValue;
    193.             }
    194.             if (item.itemAttributes[i].attributeName == "Hunger")
    195.             {
    196. //                if ((fpsPlayer.hungerPoints + item.itemAttributes[i].attributeValue) > fpsPlayer.usePlayerHunger)
    197. //                    fpsPlayer.hungerPoints = fpsPlayer.usePlayerHunger;
    198. //                else
    199. //                    fpsPlayer.hungerPoints += item.itemAttributes[i].attributeValue;
    200.             }
    201.             if (item.itemAttributes[i].attributeName == "Thirst")
    202.             {
    203. //                if ((fpsPlayer.thirstPoints + item.itemAttributes[i].attributeValue) > fpsPlayer.usePlayerThirst)
    204. //                    fpsPlayer.thirstPoints = fpsPlayer.usePlayerThirst;
    205. //                else
    206. //                    fpsPlayer.thirstPoints += item.itemAttributes[i].attributeValue;
    207.             }
    208.         }
    209.  
    210.            UpdateHUDBar();
    211.  
    212.     }
    213.  
    214.     public void OnGearItem(Item item)
    215.     {
    216.         for (int i = 0; i < item.itemAttributes.Count; i++)
    217.         {
    218.             if (item.itemAttributes[i].attributeName == "Health")
    219.                 fpsPlayer.maximumHitPoints += item.itemAttributes[i].attributeValue;
    220.             if (item.itemAttributes[i].attributeName == "Hunger")
    221.                 fpsPlayer.hungerPoints += item.itemAttributes[i].attributeValue;
    222.             if (item.itemAttributes[i].attributeName == "Thirst")
    223.                 fpsPlayer.thirstPoints += item.itemAttributes[i].attributeValue;      
    224.         }
    225.         {
    226.             UpdateHUDBar();      
    227.         }
    228.     }
    229.  
    230.     public void OnUnEquipItem(Item item)
    231.     {
    232.         for (int i = 0; i < item.itemAttributes.Count; i++)
    233.         {
    234.             if (item.itemAttributes[i].attributeName == "Health")
    235.                 fpsPlayer.maximumHitPoints -= item.itemAttributes[i].attributeValue;
    236.             if (item.itemAttributes[i].attributeName == "Hunger")
    237.                 fpsPlayer.hungerPoints -= item.itemAttributes[i].attributeValue;
    238.             if (item.itemAttributes[i].attributeName == "Thirst")
    239.                 fpsPlayer.thirstPoints -= item.itemAttributes[i].attributeValue;
    240.         }
    241.         {
    242.             UpdateHUDBar();      
    243.         }
    244.     }
    245.    
    246.     void Update()
    247.     {
    248.         if (Input.GetKeyDown(inputManagerDatabase.CharacterSystemKeyCode))
    249.         {
    250.             if (!characterSystem.activeSelf)
    251.             {
    252.                 characterSystemInventory.openInventory();
    253.             }
    254.             else
    255.             {
    256.                 if (toolTip != null)
    257.                     toolTip.deactivateTooltip();
    258.                 characterSystemInventory.closeInventory();
    259.             }
    260.         }
    261.  
    262.         if (Input.GetKeyDown(inputManagerDatabase.InventoryKeyCode))
    263.         {
    264.             if (!inventory.activeSelf)
    265.             {
    266.                 mainInventory.openInventory();
    267.             }
    268.             else
    269.             {
    270.                 if (toolTip != null)
    271.                     toolTip.deactivateTooltip();
    272.                 mainInventory.closeInventory();
    273.             }
    274.         }
    275.  
    276.         if (Input.GetKeyDown(inputManagerDatabase.CraftSystemKeyCode))
    277.         {
    278.             if (!craftSystem.activeSelf)
    279.                 craftSystemInventory.openInventory();
    280.             else
    281.             {
    282.                 if (cS != null)
    283.                     cS.backToInventory();
    284.                 if (toolTip != null)
    285.                     toolTip.deactivateTooltip();
    286.                 craftSystemInventory.closeInventory();
    287.             }
    288.         }
    289.     }
    290.  
    291.  
    292. }
    But basically i need help to add health, hunger thirst to player, i tryed to use the code from pickup water, health, food scripts but i cant get it too work properly, (the code in now will get errors, i was trying different things, so just commented it out to save time)

    this is the main part to change
    Code (CSharp):
    1. public void OnConsumeItem(Item item)
    2.     {
    3.         for (int i = 0; i < item.itemAttributes.Count; i++)
    4.         {
    5.             if (item.itemAttributes[i].attributeName == "Health")
    6.             {
    7. //                if ((fpsPlayer.hitPoints + item.itemAttributes[i].attributeValue) > fpsPlayer.maximumHitPoints)
    8. //                    fpsPlayer.hitPoints = fpsPlayer.maximumHitPoints;
    9. //                else
    10. //                    fpsPlayer.hitPoints += item.itemAttributes[i].attributeValue;
    11.             }
    12.             if (item.itemAttributes[i].attributeName == "Hunger")
    13.             {
    14. //                if ((fpsPlayer.hungerPoints + item.itemAttributes[i].attributeValue) > fpsPlayer.usePlayerHunger)
    15. //                    fpsPlayer.hungerPoints = fpsPlayer.usePlayerHunger;
    16. //                else
    17. //                    fpsPlayer.hungerPoints += item.itemAttributes[i].attributeValue;
    18.             }
    19.             if (item.itemAttributes[i].attributeName == "Thirst")
    20.             {
    21. //                if ((fpsPlayer.thirstPoints + item.itemAttributes[i].attributeValue) > fpsPlayer.usePlayerThirst)
    22. //                    fpsPlayer.thirstPoints = fpsPlayer.usePlayerThirst;
    23. //                else
    24. //                    fpsPlayer.thirstPoints += item.itemAttributes[i].attributeValue;
    25.             }
    26.         }
    i'm thinking it can be pretty simple but im a complete noob at coding xd, thanx if you would like to help

    EDIT! Ok guys i done it :D, now to do weapons
    this is code to add
    Code (CSharp):
    1.  public void OnConsumeItem(Item item)
    2.     {
    3.         for (int i = 0; i < item.itemAttributes.Count; i++) {
    4.             if (item.itemAttributes [i].attributeName == "Health") {
    5.                 if (fpsPlayer.hitPoints < fpsPlayer.maximumHitPoints) {
    6.                     fpsPlayer.HealPlayer (item.itemAttributes [i].attributeValue);
    7.                 }
    8.             }
    9.             if (item.itemAttributes [i].attributeName == "Hunger") {
    10.                 if (fpsPlayer.hungerPoints - item.itemAttributes [i].attributeValue > 0.0) {
    11.                     fpsPlayer.UpdateHunger (-item.itemAttributes [i].attributeValue);
    12.                 } else {
    13.                     fpsPlayer.UpdateHunger (-fpsPlayer.hungerPoints);  
    14.                 }
    15.             }
    16.             if (item.itemAttributes [i].attributeName == "Thirst") {
    17.                 if (fpsPlayer.thirstPoints > 0.0f && fpsPlayer.usePlayerThirst) {
    18.                        
    19.                     if (fpsPlayer.thirstPoints - item.itemAttributes [i].attributeValue > 0.0) {
    20.                         fpsPlayer.UpdateThirst (-item.itemAttributes [i].attributeValue);
    21.                     } else {
    22.                         fpsPlayer.UpdateThirst (-fpsPlayer.thirstPoints);  
    23.                     }
    24.                 }
    25.             }
    26.         }
    27.  
    28.            UpdateHUDBar();
    29.  
    30.     }
    i spent all day trying, then something poped into my head and it worked xd, u also need to create or what i did is just rename the AttributeDatabase to 4 in size then leave top one blank, and add Health Hunger Thirst in the 3 rows left. a Working inventory :D
     
    Last edited: Sep 24, 2015
  42. QuadMan

    QuadMan

    Joined:
    Apr 9, 2014
    Posts:
    122
    Hi Guys.
    I'm trying to change Impact Particle.
    When I set it and play it, It is work fine JUST FIRST TIME
    And next, there's no Impact particle
    Help me...
     
  43. pihey

    pihey

    Joined:
    Dec 28, 2014
    Posts:
    1
    Hi,
    can someone help me to make a Checkpoint for my game?
    there's a tutorial of it but it's for older version of RFPS
     
  44. Ratboy601

    Ratboy601

    Joined:
    Jun 22, 2014
    Posts:
    29
    Deleted User, TonyLi and QuadMan like this.
  45. NeuroToxin-Studios

    NeuroToxin-Studios

    Joined:
    Dec 7, 2014
    Posts:
    68
    Ratboy601 likes this.
  46. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,670
    Likewise, great game! The puzzle progression was well designed, and the player character's commentary was well written. I like how the music changed when you reached different stages. I'm looking forward to playing the whole game!
     
    Deleted User and Ratboy601 like this.
  47. Deppex

    Deppex

    Joined:
    May 31, 2015
    Posts:
    21
    SOLVED

    I have a weird problem with AI.
    If Ai attacking player
    and player is lower than AI

    Then I get this Warning against
    and AI is still not responding.

    Look rotation viewing vector is zero
    UnityEngine.Quaternion:LookRotation(Vector3)
    <RotateTowards>c__IteratorB:MoveNext() (at Assets/RFPSP/Scripts/AI/AI.cs:720)


    Code (CSharp):
    1. //rotate to face target
    2.     IEnumerator RotateTowards( Vector3 position  ){
    3.         float turnTime;
    4.         turnTime = Time.time;
    5.  
    6.         SetSpeed(0.0f);
    7.         agent.Stop();
    8.  
    9.         while(turnTime + 4.0 > Time.time){
    10.             turning = true;
    11.  
    12.             if(pursueTarget){
    13.                 position = FPSWalker.leanObj.transform.position;
    14.             }else{
    15.                 if(target){
    16.                     lastVisibleTargetPosition = target.position + (target.up * targetEyeHeight);
    17.                 }else{
    18.                     lastVisibleTargetPosition = position;
    19.                 }
    20.             }
    21.        
    22.             Vector3 direction = lastVisibleTargetPosition - myTransform.position;
    23.             direction.y = 0;
    24.  
    25.             // Rotate towards the target
    26.             // This is problem ??????????????
    27.           myTransform.rotation = Quaternion.Slerp (myTransform.rotation, Quaternion.LookRotation(direction), rotationSpeed * Time.deltaTime * 4);
    28.             myTransform.eulerAngles = new Vector3(0, myTransform.eulerAngles.y, 0);
    29.             yield return 0;
    30.  
    31.         }
    32.         turning = false;
    33.     }
    This is the solution.
    Code (CSharp):
    1. IEnumerator RotateTowards( Vector3 position  ){
    2.         float turnTime;
    3.         turnTime = Time.time;
    4.  
    5.         SetSpeed(0.0f);
    6.         agent.Stop();
    7.  
    8.         while(turnTime + 4.0 > Time.time){
    9.             turning = true;
    10.  
    11.             if(pursueTarget){
    12.                 position = FPSWalker.leanObj.transform.position;
    13.             }else{
    14.                 if(target){
    15.                     lastVisibleTargetPosition = target.position + (target.up * targetEyeHeight);
    16.                 }else{
    17.                     lastVisibleTargetPosition = position;
    18.                 }
    19.             }
    20.            
    21.             Vector3 direction = lastVisibleTargetPosition - myTransform.position;
    22.             direction.y = 0;
    23.             if(direction.x != 0 && direction.z != 0){
    24.                 // Rotate towards the target
    25.                 myTransform.rotation = Quaternion.Slerp (myTransform.rotation, Quaternion.LookRotation(direction), rotationSpeed * Time.deltaTime * 4);
    26.                 myTransform.eulerAngles = new Vector3(0, myTransform.eulerAngles.y, 0);
    27.                 yield return 0;
    28.             }else{
    29.                 target = null;
    30.             }
    31.         }
    32.         turning = false;
    33.     }

     
    Last edited: Oct 1, 2015
  48. Ratboy601

    Ratboy601

    Joined:
    Jun 22, 2014
    Posts:
    29
    Thanks guys! glad you liked it! I'll definitely keep you updated here. You can follow it on IndieDB too if you want. We're gonna submit it to SteamGreenlight soon too.
     
  49. llJIMBOBll

    llJIMBOBll

    Joined:
    Aug 23, 2014
    Posts:
    578
    here i fixed a mistake, if the amount of health you were applying was more than allowed it wouldn't add any health at all, heres the fix
    Code (CSharp):
    1. if (item.itemAttributes [i].attributeName == "Health")
    2.             {
    3.                 if ((fpsPlayer.hitPoints + item.itemAttributes [i].attributeValue) > fpsPlayer.maximumHitPoints)
    4.                     fpsPlayer.hitPoints = fpsPlayer.maximumHitPoints;
    5.                 else
    6.                     fpsPlayer.hitPoints += item.itemAttributes [i].attributeValue;
    7.             }
    im just trying to sort out the hunger and food doesnt seem to work now, it did do tho or maybe i made a mistake somewhere...
    i do need some help tho, when my player has 0 health the input goes all weird and cant move, do i need to add a die function? or call it in update if health is below 0?


    thanx again :D
     
  50. llJIMBOBll

    llJIMBOBll

    Joined:
    Aug 23, 2014
    Posts:
    578
    i added a highscore to the scoremanager someone posted, it will save and load the highscore too. thought i'd share :D

    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.UI;
    3. using System.Collections;
    4.  
    5. public class ScoreManager : MonoBehaviour
    6. {
    7.     public static int score = 0;
    8.     public Text scoreText;
    9.     public static int highScore = 0;
    10.     public Text  highScoreText;
    11.  
    12.     //Resets score and Loads highest score
    13.     void Start()
    14.     {
    15.         score = 0;
    16.         highScore = PlayerPrefs.GetInt ("highScore", 0);
    17.     }
    18.  
    19.     //Updates all the goodness!!!
    20.     void Update()
    21.     {
    22.         if(score > highScore) {
    23.             highScore = score;
    24.         }
    25.         scoreText.text = "SCORE: " + score;
    26.         highScoreText.text = "HIGHSCORE: " + highScore;
    27.     }
    28.  
    29.     //Saves highest score
    30.     void OnDisable() {
    31.         PlayerPrefs.SetInt ("highScore", highScore);
    32.         PlayerPrefs.SetInt ("score", score);
    33.     }
    34.  
    35.     //Use with UI button to load score manually
    36.     public void LoadScore() {
    37.         highScore = PlayerPrefs.GetInt ("highScore", 0);
    38.         score = PlayerPrefs.GetInt ("score", 0);
    39.     }
    40.  
    41.     //Use with UI button to save score manually
    42.     public void SaveScore() {
    43.         PlayerPrefs.SetInt ("highScore", highScore);
    44.         PlayerPrefs.SetInt ("score", score);
    45.     }
    46.  
    47.     //Use with UI button to clear highScore
    48.     public void clearScore(){
    49.         //PlayerPrefs.DeleteAll();
    50.         if (PlayerPrefs.HasKey ("highScore")) {
    51.             PlayerPrefs.DeleteKey ("highScore");
    52.             setScore();
    53.             Debug.Log ("ClearedScore");
    54.         }
    55.     }
    56.  
    57.     //Resets highScore to 0, or current score if higher than 0
    58.     void setScore() {
    59.         highScore = 0;
    60.         //highScore = score;
    61.     }
    62. }