Search Unity

  1. Check out our Unite Austin 2017 YouTube playlist to catch up on what you missed. More videos coming soon.
    Dismiss Notice
  2. Unity 2017.2 is now released.
    Dismiss Notice
  3. The Unity Gear Store is here to help you look great at your next meetup, user group or conference. With all new Unity apparel, stickers and more!
    Dismiss Notice
  4. Introducing the Unity Essentials Packs! Find out more.
    Dismiss Notice
  5. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice
  6. Unity 2017.3 beta is now available for download.
    Dismiss Notice

Realistic FPS Prefab [RELEASED]

Discussion in 'Assets and Asset Store' started by Azuline-Studios, Apr 5, 2013.

  1. Azuline-Studios

    Azuline-Studios

    Joined:
    Apr 5, 2013
    Posts:
    203
    The Realistic FPS Prefab is an easy way to implement the core features of first person games into your Unity projects with a few mouse clicks. Set up is quick and just requires dragging and dropping the FPS object into your scene and assigning a layer to collision geometry. The asset has been designed with a focus on keeping scripts simple and ensuring that motion and effects are smooth and glitch free. The Realistic FPS Prefab is a great learning tool and template for FPS games.



    Try the Web Player Demo

    Asset Store Link

    What features does the Realistic FPS Prefab offer?
    Full physics interaction with a rigidbody character controller that has mass in the game world. Pick up and throw objects, ride elevators and horizontal platforms, create physics puzzles, and climb ladders.

    Player state handling for sprinting, crouching, and jumping movement states with seamless transitions, easily configurable speeds, and air manipulation. Player health management with damage from falling, enemy fire, and elevators is also included.

    Advanced weapon positioning using sine bobs, iron sights, weapon sway, position changes based on player movement state, and animation for actions like reloading and readying weapons.

    Camera movement effects such as weapon fire, landing, and pain kicks, as well as camera view animation to accompany weapon actions like reloading. Fully configurable sine bobbing based on player movement states is also supported.

    Weapon behavior customization allows switchable auto and semi auto modes, shotguns, scoped weapons, accuracy handling, single shell reloading, and melee weapons by modifying the variables of one script instance from the editor - no additional scripting required to make a new weapon.

    Item pickups to place in your scene for ammo, health, and weapons that can either be static or moveable (and throwable) rigidbodies.

    Weapon effects like bullet impacts, smoke, tracers, and ejecting casings with simple variables to control size, velocity, and ejection delay of shells.

    Ease of use through extensive documentation and commented code, simple drag and drop functionality of game objects into scenes, compatibility with version 3.5 and higher of Unity free and professional, and customization variables accessible from the inspector.

    An example sandbox scene with an improved default AI for testing.​

    Are there any more features planned?
    Yes, we plan to continue adding features and improving the asset however we can. The addition of explosives, bows and arrows, expanded AI, and third person mode are possible in the future.

    Version Notes

    1.19
    -Fixed AI search range not increasing after being attacked by player.
    -Updated coroutine return and break statements to prevent errors when building for Windows 8 Store.
    -Applied layer changes to the Glass prefab to allow it to take damage after being placed from the Project Library.
    -Added cameraIdleBob and cameraSwimBob vars to Ironsights.cs to allow customization of vertical bobbing of view while idle or swimming.
    -Added staminaDepleted var to FPSRigidBodyWalker.cs to disable sprinting if stamina is fully depleted and sprintRegenWait is true. This is done to prevent the player from sprinting for short times if stamina is low.

    1.18
    -Removed animation check var in CameraKick.cs to prevent rare occurrences of camera being unaligned.
    -Replaced GetCurrentProcess() call for quit button with Application.Quit since it has been fixed.
    -Modified smoke texture so its alpha mask will be properly read in newer versions of Unity.
    -Added smoothing to sprinting animation playback for better motion transition.
    -Fixed playerHeightMod values between 1.0 and 2.0 not allowing player to move.
    -Added option for regenerating health.
    -Backwards sprinting is now prevented.
    -Increased item pickup raycast length slightly to make activating scaled-down weapon pickups easier.
    -Added ApplyDamage function parameters for more realistic NPC ragdoll behavior.
    -Optimized shotgun impact particle effects played on NPCs.
    -Improved timing of ejected shell rotation.
    -Added options for hiding weapon when player is underwater or holding an object.
    -Added inaccuracy var to NPCAttack.cs to allow enemies to miss on their attacks.
    -Made automatic weapon's recoil spread recover when the fire button is released instead of waiting for semi auto shot timer.
    -Added optional player hunger and thirst attributes which are reduced by apple and canteen pickups
    -Updated uncrouching obstacle check to prevent player from uncrouching into overhead geometry in some situations.
    -Hard-coded the raycast slope limit angle in FPSRigidBodyWalker.cs to 60 to prevent player from getting stuck in small indents or tight spaces (the capsule check slope limit can still be customized).
    -Scripts now prevent dragging objects while player is zoomed or dead.
    -Added kick back amount variables to WeaponBehavior.cs to allow slight backward motion of weapon during sustained fire.
    -Weapon z position (forward back) for zoomed, unzoomed, and sprinting states are now customizable from the inspector.
    -Added removePrefabRoot bool to WorldRecenter.cs script and deleted RemovePrefabRoot.cs script to allow option for keeping the FPS Main prefab root object or deleting it on scene load to allow the world recenter script to keep the FPS Player object's local and world coordinates synchronized to prevent spatial jitter and allow larger scenes.
    -Converted AI scripts from javascript to C# to allow easier compilation for android and windows projects and better communication between scripts.
    -Added walkBobAmountX and walkBobAmountY vars to WeaponBehavior.cs for customization of walking bob amounts per weapon.
    -Added walkBobYawAmount, CrouchBobYawAmount, ZoomBobYawAmount, and SprintBobYawAmount vars to -Ironsights.cs to allow camera yaw angle bobbing.
    -Changed SendMessage call for ApplyDamage() functions to direct function calls identified by game object layer.
    -The sprintRegenWait and sprintRegenTime variables of FPSRigidbodyWalker.cs can now be used to disable the sprinting button until sprintRegenTime has elapsed and sprinting stamina is fully regenerated.
    -Added drownDamage var to FPSRigidBodyWalker.cs to set the rate that player takes drowning damage.
    -Restored functionality of crosshairEnabled and aimingReticle vars of FPSPlayer.cs to allow customization of aiming crosshair display.

    1.17
    -Made weapon sprinting animation return to center sooner after player starts falling.
    -Unhid the mouse cursor when paused (or timescale = 0).
    -Added collider sweep in front of player to allow better jumping over stationary obstacles.
    -Fixed sights not rising if sprint is cancelled, but sprint and forward buttons are still held.
    -Added an extra check to make animated camera angle values return to zero when not playing animations. This prevents rare occurrences of the weapon and camera becoming misaligned.
    -Added muzzleLightDelay to WeaponBehavior.cs to define delay before muzzle light begins fading.
    -Added muzzleLightReduction to WeaponBehavior.cs to define speed of muzzle light fading.
    -Changed name of "childNum" var in PlayerWeapons.cs to "currentWeapon" for clarity.
    -Added defaultFov var to Ironsights.cs to allow the default camera FOV to be customized.
    -Added sprintFov var to Ironsights.cs to allow the camera FOV while sprinting to be customized.
    -Added weaponCamFovDiff var to Ironsights.cs to allow the weapon camera FOV to be customized. This value is subtracted from the main camera FOV to control the perspective of weapon models.
    -New Footsteps.cs script defines different footstep sounds and landing sounds per surface tpye.
    -New WeaponEffects.cs script defines weapon impact effects, impact marks, and weapon impact sound effects per surface type.
    -Moved weapon effect vars and functions from WeaponBehavior.cs to new WeaponEffects.cs script.
    -Pain Screen Kick Amt of FPSPlayer.cs now can be used to set magnitude of screen kicks when player takes damage.
    -Added the var myWaypointGroup to AI.js and added the waypointGroup var to AutoWayPoint.js script to set waypoint groups for NPC patrols.
    -Fixed doPatrol behavior in AI.js so NPCs stand watch if not patrolling.
    -RandomSpawnChance of AI.js can be used to make NPCs have a random chance of spawning.
    -Airborn NPC character controllers now move to the ground when scene is loaded.
    -Added waypointNumber var to AutoWayPoint.js to define the path order of waypoints that the NPC will patrol starting from number 1 and returning from the last numbered waypoint in the waypoint path group.
    -Locked mouselook roll in SmoothMouseLook.cs to prevent gun rotating with fast mouse movements.
    -Player can now drop weapons with the droppable value set to true in WeaponBehavior.cs.
    -Player now drops weapon, falls down, and is affected by physics forces on death.
    -Added addsToTotalWeps bool to WeaponBehavior.cs and backupWeapon int to PlayerWeapons.cs to allow player's backup weapon to be skipped in auto weapon selection during weapon drops and swaps, to make the backup weapon not be counted toward player's weapon total, and to prevent the backup weapon from being dropped.
    -The maxWeapons int in PlayerWeapons.cs now defines the maximum amount of weapons that can be held at one time.
    -WeaponPickup.cs will now read its removeOnUse bool and the dropWillDupe bool in WeaponBehavior.cs to determine if the current weapon should be dropped or destroyed when picking up a new weapon.
    -The player's crosshair now changes to an "X" reticle if the player can't pick up the weapon under the crosshair, such as when the player has already picked up the weapon from an armory (dropWillDupe set to true) and can't drop the weapon due to this allowing ammo duplication exploit.
    -Added unique Texture2D vars to item pickup scripts to allow custom pickup reticles/icons.
    -Added showAimingCrosshair to WeaponBehavior.cs to selectively disable aiming crosshair for weapons like sniper rifles.
    -Added useSwapReticle var to FPSPlayer.cs to toggle the display of the swap reticle if the weapon pickup under player's crosshair will be switched or swapped with current weapon.
    -Improved cancelling of non-magazine reload if fire button is pressed and player has loaded at least 2 shells/bullets.
    -Prevented switching weapon during non-magazine reload from causing neutral anim glitch and delay at the start of next reload for that weapon.
    -playerHeightMod and crouchHeightPercentage in FPSRigidbodyWalker.cs will now control standing and crouching height of player.
    -WaterZone.cs script can be attached to a box trigger collider to control player swimming and water effects.
    -Added MarkDuration to FadeOutDecals.cs to define the time that impact marks should stay before fading.
    -WorldRecenter.cs now prevents spatial jitter of game objects due to floating point precision loss and allows much larger scenes to be used.
    -Made objects that are set to layer 9, the "Ragdoll or Usable" layer, run any ActivateObject() functions in their scripts if the player presses the use button when object is in the crosshair.
    -By default, the P button now pauses the game.
    -barrelSmokeShots in Weaponbehavior.cs now defines number of shots required to make smoke rise from gun barrel.
    -Glass surface type added with its own BreakGlass.cs script and prefab.
    -MineExplosion.cs can be attached to a game object to create landmines.
    -ExplosiveObject.cs can be attached to a game object to make it explode after being damaged.
    -Made the zoom and sprint button behaviors selectable between toggle, hold, or both (tap to toggle, press to hold).
    -MonsterItemTrap.cs can be used to spawn enemies and create ambushes when player activates or uses an item.
    -MonsterTrigger.cs can be used to spawn enemies and create ambushes when player enters a trigger zone.
    -EdgeClimbTrigger.cs can be attached to a trigger near a ledge to allow the player to climb themselves up it.
    -EdgeClimbTriggerActivate.cs can be used to create a trigger that will reactivate a vault trigger that has disabled its collider after player has vaulted from it.
    -Fixed non magazine reloads with bulletsToReload amount greater than 1 not counting reloaded bullets correctly.
    -Made jump and crouch buttons move player up and down a ladder trigger if they aren't holding a forward or backward move button already.
    -Added Zombie NPC prefab with animations, sound, and ragdoll.
    -targetPlayer var of Ai.js will now determine if NPC should ignore player.
    -Made the raycast length for item pickups scale with the playerHeightMod amount.
    -The attack range of NPCs will now be reduced by the crouchRangeMod amount of AI.js when player is crouching.
    -The useAxisInput var of FPSPlayer.cs will now allow the player to use Unity’s built in horizontal and vertical axes for movement (for joysticks or virtual joysticks).


    1.16
    -Made changes to several scripts to allow Time.timescale to be set to 0 (for game pausing) and back to a positive value.
    -Changed the input smoothing method in SmoothMouseLook.cs
    -Added shellRldAnimSpeed var to WeaponBehavior.cs to allow per-weapon customization of animation speed for reloading single shells/bullets.
    -Added DisappearOnUse var to all pickup scripts which can be unchecked to make pickups stay after use (for making armories, ammo crates, etc.)

    1.1
    -Added a sniper rifle and pickups to demonstrate scoped weapons.
    -Attack Range variable of AI.js is now properly taken into account for determining when to attack the player.
    -Fixed raycast calculation in DragRigidbody.cs so user won’t have to click outside and back in the running game window in the editor to drag rigidbodies.
    -Fixed rigidbodies keeping high drag values resulting in objects falling slowly.
    -Controls can now be easily set from the inspector in the FPSPlayer.cs script on the FPS Player object
    -Added swayAmountZoomed variable to WeaponBehavior.cs to control zoomed weapon sway which can be used for reducing the zoomed sway of scoped weapons.
    -Added swayAmountUnzoomed variable to WeaponBehavior.cs to allow customization of unzoomed sway amount for individual weapons.
    -Miscellaneous inspector visibility cleanup.

    1.05
    -Added CameraRollAmt variable to CameraKick.cs to allow for animation of camera roll angles (currently used in melee weapon camera swings).
    -Changed Ironsights button behavior to tap to toggle and press to hold.
    -Decreased default zoom bobbing and removed weapon lowering effect for smoother view weapon model movement when zoomed and walking.
    -Improved frame rate independence of bobbing transitions in Ironsights.cs.
    -Fixed shotgun last reload anim from using reload speed instead of last reload speed when ammo was 1.
    -Increased Melee hit detection area by using a sphere cast instead of ray cast.
    -Rotation and scale of hit marks now remain consistent even if parent object is unevenly scaled in editor.
    -Updated onscreen F1 help text.

    1.0
    -Initial Release


    Upcoming Features
    -Merge use item (default E) and drag rigidbody (default Z) keys
    -Player leaning
    -Grenades/explosives
    -Thirdperson mode
    -Improved input method
    -Expanded AI behaviors
    -And more on the way
     
    Last edited: Apr 23, 2016
  2. ProjectOne

    ProjectOne

    Joined:
    Aug 9, 2010
    Posts:
    442
    Hi, that looks good, nice asset.
    1- The one thing I felt missing was the typical 'Q and E on keyboard to peek/see around corner.
    2- Any part of your code u think it won't be compatible with iOS?
    3- Will u be adding touch-control for mobile devices from out of the box compatibility?
    4- guns currently used in your web demo, are they included in the asset and ok to use for our own games?

    Thanks
     
  3. Azuline-Studios

    Azuline-Studios

    Joined:
    Apr 5, 2013
    Posts:
    203
    Thanks ProjectOne, Q and E leaning is a good idea and I’ll add it to the list of upcoming features.

    This asset was developed with a focus on the desktop platform and IOS compatibility hasn’t been tested as I don’t have access to the licenses, but we have tested for functionality and framerate independence on a variety of desktop systems with success. As far as I know, the only part of the code that would affect performance on slower hardware is the fixed time step value, which is set to 0.01 (100 FPS) for smoother physics instead of the Unity default 0.02 (50 FPS).

    On an Intel 1.8GHz dual core, there hasn’t been a noticeable decrease in performance, but a 0.02 fixedDeltaTime value could be used for mobile development. The rigidbody movements won’t be as smooth and the push forces would have to be lowered, but all runs well using both 0.01 and 0.02 fixedDeltaTime values.

    Ideally, the asset would use the default 0.02 fixedDeltaTime, but ragdolls and rigidbodies that have their parents modified during runtime seem to loose their interpolation. Still looking into whether it is my code or a quirk in how the physics are calculated In Unity. A decrease in the fixed time step might not even be noticeable on smaller screens.

    The only other issue I can think of would be if Unity has to use lower precision floating points on mobile. If the player travels 1000 or -1000 units from the origin, positional inaccuracies (spatial jitter) start to show up. I’m looking into a fix for this, which involves moving all objects back to the origin, but it isn’t high priority because 2000² units is a decent amount of room to work with.

    These pages describe the topic pretty well:

    http://pompidev.net/2012/12/21/3d-graphics-quality-and-floating-point-accuracy-on-android/

    http://answers.unity3d.com/questions/54739/any-solution-for-extreamly-large-gameworlds-single.html

    A simple work-around would just be to place the player at the origin or around a -500 x or y position and have them move into positive x and y values, but not exceeding the range that causes spatial jitter. Lower floating point precision might not even be an issue on mobile, but it’s something to be aware of.

    As far as out of the box touch controls, it’s a possibility, but it wouldn’t be for a while because I don’t have a way to test code on mobile yet. The way player input is handled in this asset is fairly simple and I imagine it would just involve setting up the touch button/virtual pad code and piping it into the Input.GetKey references in the scripts. We are also available for support if you have any questions about how the input code works.

    The gun models were put together using Creative Commons licensed models and animated by us, so they should be ok to use in your games.

    Hope that answers your questions.
     
  4. TheRealFuzz

    TheRealFuzz

    Joined:
    Jul 17, 2012
    Posts:
    309
    This looks really cool but I'd like to ask a few questions first before I buy it. Do you know if any of the scripts are compatible with Ultimate FPS Controller, such as your ladder scripts and you physics pick up? :)
     
  5. lod3

    lod3

    Joined:
    Mar 21, 2012
    Posts:
    514
    Curious as well.
     
  6. ProjectOne

    ProjectOne

    Joined:
    Aug 9, 2010
    Posts:
    442
    Thank u for your clear reply Azuline. Good stuff
     
  7. Azuline-Studios

    Azuline-Studios

    Joined:
    Apr 5, 2013
    Posts:
    203
    Thanks TheRealFuzz and lod3. The ladder script was designed to have the least amount of code as possible (for efficiency if there are a lot of ladders/climbing surfaces) and just sets a climbing boolean value in the character controller script to true or false. The character controller then uses the climbing value to determine when to add vertical climbing speed to the total player velocity.

    So to add our asset’s ladder climbing the Ultimate FPS Camera, you would need to locate where total player velocity is calculated in the character controller and adapt the appropriate code there from our project. I’m not sure if the Ultimate FPS Camera uses a rigidbody character controller, but if it does, the rigidbody.velocity could be set to something like Vector3(velocity.x, climbSpeedAmt, velocity.z);

    We could have made the ladder climbing script more self contained and portable without so much integration with the charater controller, but it wouldn’t be optimal if there are a lot of ladders in the scene whereas the character controller has just one instance in the scene and has access to other variables that affect player velocity.

    On the other hand, the rigidbody dragging/physics pick up script is more portable and can be added to another character controller object with an attached rigidbody.

    We’ve made a lot of effort organizing our code in a way that is easy to understand so that it can be modified and used as a learning tool for Unity. We are also available for support if you have questions.
     
  8. TheRealFuzz

    TheRealFuzz

    Joined:
    Jul 17, 2012
    Posts:
    309
    Thanks for the reply! I think I may have to take a chance and grab this asset :)

    Also, any idea how compatible this is with networking?
     
    Last edited: Apr 6, 2013
  9. Kuroato

    Kuroato

    Joined:
    Aug 19, 2012
    Posts:
    1,646
    Wow! this is pretty awesome! = ) I'll need to get this one really soon. Good job! and Thank you for such a Great Asset! Only I would suggest maybe changing your Assets Category, I would think this goes under Complete Project / Template Category, instead of just Scripting. You may want to update this to ensure you get sales from people who are not on the forums and looking through that category for more complete assets like this one.
     
  10. Kuroato

    Kuroato

    Joined:
    Aug 19, 2012
    Posts:
    1,646
    Questions... I see you include a bot with AI.

    Does the AI use Path-finding (+navmesh), with a Node Grid setup or something? is does it work without these...?

    and finally can you somehow tweak the include AI to work for Zombie's that do Close Range Damage, instead of Long Ranged (since zombies don't shoot lol!) please do let me know.
     
  11. TheRealFuzz

    TheRealFuzz

    Joined:
    Jul 17, 2012
    Posts:
    309
    So I bought it and everything is working pretty well but I have a problem. When I use the rigid body grab script, when I drop objects they fall to the ground really slowly instead of fast.
     
  12. Azuline-Studios

    Azuline-Studios

    Joined:
    Apr 5, 2013
    Posts:
    203
    Thank you TheRealFuzz, networking hasn’t been tested with this asset, but I assume that it would be compatible. I haven’t delved into networking with Unity yet and the only problem I can think of might be with the rigidbodies. A lot of physics calculations would mean higher latency, so if there was a way to selectively make some of the physics (like bullet shells and ragdolls) client side, networking would be faster.

    For the rigidbody falling problem, are you using a new scene, or is this happening in the included sandbox scene? You might want to check that your gravity setting in Edit->Project Settings->Physics is set to something like 0, -9.8, 0. Also, on the rigidbody component of the object you are dropping, is the drag value set to something high like over 0.6 or so? Or is the rigidbody’s mass set to a very low value? You might also want to check if the fixed timestep value in Edit->Project Settings->Time is anything other than 0.01 or 0.02 when running the scene in the editor.

    Either one of those could cause slow rigidbody falling. If you are still experiencing the issue could you please post, email, or PM me with specific details about what happens when you try to drop the rigidbody, like if you are running the scene in the editor or standalone, if there any printed errors, or unexpected movements of objects? I appreciate the feedback TheRealFuzz!

    Kurato, this asset does seem to be more of a complete project/template , I’ll have to change the asset category for the next update :)

    The included AI doesn’t use pathfinding or Unity’s navmesh. The main focus of this project is FPS player mechanics, so the AI is there just for testing at the moment. The next step to improving the AI would be to either use Unity’s navmesh or incorporate a third-party pathfinding solution like simple path. An option to have the AIs select random points to wander to would also be a good addition.

    The current AI uses waypoints that define a patrol path which they follow until they see the player. If the Do Patrol check box of the AI.js script is not clicked, they simply stand watch until they see the player. When the player is in view, they run after the player and attack, but once their line of sight is blocked, they walk back to their patrol path or original position.

    To turn the current enemies into melee attacking zombies, you first need to change the Shoot Range and Dont Come Closer Range values in the AI.js script instance of the enemy object to 2.

    In the next update, that’s all that you’ll need to do, but the current version, you also need to change the AI.js script starting at line 113 from:

    Code (csharp):
    1.             if(distance > shootRange * 3){
    2.                 speedAmt = 1.0f;
    3.                 return;
    4.             }
    to

    Code (csharp):
    1.             if(distance > attackRangeAmt){
    2.                 speedAmt = 1.0f;
    3.                 return;
    4.             }  
    And the enemy will run up close before they start attacking. The Attack Range value determines at what range they will see the player and start attacking. Maybe I will include melee enemies in a future update, all that's needed is a zombie model with a melee attack animation and a different sound effect.
     
    Last edited: Apr 7, 2013
  13. TheRealFuzz

    TheRealFuzz

    Joined:
    Jul 17, 2012
    Posts:
    309
    Thanks for getting back to me. I just tested the example that came with this asset and I can confirm that objects slowly fall down in the example scene. I've check all the values that you've suggested and still no luck, I'll keep searching and see if I can fix it.
     
  14. Azuline-Studios

    Azuline-Studios

    Joined:
    Apr 5, 2013
    Posts:
    203
    I see what the problem is now. The Drag Rigidbody script increases the drag of an object when you pick it up so it won't spin around excessively when you move the mouse. The script usually changes the drag back to it's original value, but for some reason it's missing that step, or overwriting the original drag value and the object is keeping the high drag value (10 by default). I've never seen this happen until I was working on something else with this script. Really sorry about this. I've checked for, and fixed all the problems I could find, but this is one of those bugs that is hard to track down because it shows up somewhat randomly. I'll let you know once I find a fix, so you won't have to wait for the update.
     
  15. TheRealFuzz

    TheRealFuzz

    Joined:
    Jul 17, 2012
    Posts:
    309
    Thank you very much! Looking forward to it :)
     
  16. Azuline-Studios

    Azuline-Studios

    Joined:
    Apr 5, 2013
    Posts:
    203
    No problem, thank you for letting me know about the issue!

    Ok this should fix two bugs in the DragRigidbody.cs script. The next update will include these fixes, but you can apply them now if you want. Be sure to back up the original DragRigidbody.cs script before making these changes in case you make a mistake. It's also important to follow these steps in the order they are posted because I will be referring to line numbers.

    First, around line 16 change:

    Code (csharp):
    1. private float oldDrag;
    2. private float oldAngularDrag;
    3.    
    4. void Update (){
    to:

    Code (csharp):
    1. private float oldDrag;
    2. private float oldAngularDrag;
    3. private bool dragState;
    4.    
    5. void FixedUpdate (){
    then, around line 27, change:

    Code (csharp):
    1.     if(!Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit, reachDistance)){
    2.         return;
    3.     }
    to:

    Code (csharp):
    1.     if(!Physics.Raycast(Camera.main.transform.position, ((Camera.main.transform.position + Camera.main.transform.forward * reachDistance) - Camera.main.transform.position).normalized, out hit, reachDistance)){
    2.         return;
    3.     }
    then, around line 61 change:

    Code (csharp):
    1.  
    2. IEnumerator DragObject ( float distance  ){
    3.     oldDrag = springJoint.connectedBody.drag;
    4.     oldAngularDrag = springJoint.connectedBody.angularDrag;
    5.     springJoint.connectedBody.drag = drag;
    to:

    Code (csharp):
    1. IEnumerator DragObject ( float distance  ){
    2.     if(!dragState){
    3.         oldDrag = springJoint.connectedBody.drag;
    4.         oldAngularDrag = springJoint.connectedBody.angularDrag;
    5.         dragState = true;
    6.     }
    7.     springJoint.connectedBody.drag = drag;
    then, around line 69 change:

    Code (csharp):
    1.         springJoint.transform.position = ray.GetPoint(distance);
    2.         if(!Input.GetKey(KeyCode.X)){
    to:

    Code (csharp):
    1.  
    2.         Ray ray = new Ray (Camera.main.transform.position, ((Camera.main.transform.position + Camera.main.transform.forward * reachDistance) - Camera.main.transform.position).normalized);
    3.         springJoint.transform.position = ray.GetPoint(distance);
    4.         if(!Input.GetKey(KeyCode.X)){
    and finally, around line 107 change:

    Code (csharp):
    1.     springJoint.connectedBody.angularDrag = oldAngularDrag;
    2.     springJoint.connectedBody = null;  
    to:

    Code (csharp):
    1.     springJoint.connectedBody.angularDrag = oldAngularDrag;
    2.     springJoint.connectedBody = null;
    3.     dragState = false;
    If all went well, the script should compile and you should be able to start the scene in the editor and be able to drag rigidbodies without needing to left click outside the running game window and back in it again. This should also fix the rigidbody drag not being set to its original values when you let go of an object.

    Also note that the first Raycast doesn't use a layer mask and is checking all layers for hits. In the next update, this Raycast will be using a layermask. For efficiency it will only check objects that can be picked up. I excluded that part of the code to make this fix easier to apply.

    If the rigidbodies are still falling slowly or the script doesn't work, please copy the backup DragRigidbody.cs back over your modified script, and let me know so I can keep looking at the code, but I'm pretty sure this solves both problems.
     
  17. TheRealFuzz

    TheRealFuzz

    Joined:
    Jul 17, 2012
    Posts:
    309
    Thanks for going to all the trouble but I couldn't get the script to work but I'm sure it works on your end, as you can probably tell, I'm not much of a coder :p

    Would it be to much to ask for you to PM me the edited script? Otherwise I can wait for the next update.
     
  18. Kuroato

    Kuroato

    Joined:
    Aug 19, 2012
    Posts:
    1,646
    hey Azuline, I just purchased this Asset on Saturday! I was as impressed with it as I was when i saw the demo and asset features. Really Awesome man! One of my best Asset purchases to Date I must say. THANK YOU! for the above fix to turn the AI into Melee Attacking Zombies! = )

    I have a game called ZombieWarz... http://zombiewarz.com that uses Ultimate FPS Camera and a Zombie Asset, I was thinking of updating the Game using your Asset! So this Fix will be very helpful for me to at least get some Zombies in the game to see what it looks like... later I'll try to update the AI unless you manage to update the AI before I do lol. = ) anyway thanks again! awesome job on this asset and support.
     
  19. Azuline-Studios

    Azuline-Studios

    Joined:
    Apr 5, 2013
    Posts:
    203
    PM sent. Hope the updated script works better for you TheRealFuzz!

    Thank you Kuroato! Really glad that you've been enjoying the asset. A lot of time and effort has been put into this project :)

    We'll see about improving the AI, there are a few other features we're looking at first though. The AI really only needs some pathfinding added to it. The enemies work surprising well for just having linear paths to their goals. They can get stuck behind walls sometimes, but I think it helps that they have round capsule colliders as it helps them get around corners. Best of luck on your project!
     
  20. aeditz50

    aeditz50

    Joined:
    Dec 18, 2012
    Posts:
    10
    Is it possible to add your own guns?
     
  21. SkyCone131

    SkyCone131

    Joined:
    Apr 8, 2013
    Posts:
    1
    This FPS kicks a**!! Definitely, the best one on here - hands down. Great job! Appreciate the support and looking forward to the update.
     
  22. Unicron

    Unicron

    Joined:
    Sep 28, 2011
    Posts:
    191
    Wouldn't be of any use if you couldn't. Should be the same as any other FPS kits out there, gotta make sure you have the correct assets, weapon model, sounds, animations, etc.

    I'm liking this kit a lot but I'll wait it out to see what's added in the next updates, it's a few features short of perfect. Features I'd like to see added in the next updates are lean left/right, stamina, swimming (if not already in), damage handler (didn't see that listed in the features list), jumping/vaulting/climbing/hanging over obstacles (not ladders), weapons with scopes, dual wielding items/weapons,etc.
     
    Last edited: Apr 8, 2013
  23. Azuline-Studios

    Azuline-Studios

    Joined:
    Apr 5, 2013
    Posts:
    203
    Adding your own guns to the Realistic FPS Prefab is a simple process and just involves duplicating an existing weapon object, swapping out the model for one of your own, and tweaking the values of the weapon script. You can also chose to configure weapon and ammo pickups for the new weapon. Just did this for the new sniper rifle in version 1.1 and the process was pretty quick. There is a detailed tutorial in the documentation that walks you through the steps. We are also here to answer any questions you might have involving this process.

    Thank you! We're glad that you're enjoying the asset!

    Thanks Unicron, there is player damage handling done in this asset that comes into play when you fall a long distance, are hit by enemy fire, or are caught under an elevator, etc. We're updating our feature list to make this more clear. As far as scoped weapons, it's only a matter of having a weapon model with a scope ready to be imported into Unity. We just added a sniper rifle in the new update to demonstrate how scopes work in this asset. The camera zoom amount and zoomed weapon sway amount can be customized to make adding scoped weapons a quick process. Most of the other features you mentioned are on the way. If you have any questions, please let us know!


    The new Realistic FPS Prefab 1.1 update is being uploaded today and should be live soon. It adds a sniper rifle and involves a few minor fixes of the AI and rigidbody dragging code as well as the addition of configurable controls from the inspector and two new variables to customize zoomed and unzoomed weapon sway for each weapon (useful for scoped weapons or other kinds of optics). Here are the specific changes for version 1.1:

    -Added a sniper rifle and pickups to demonstrate scoped weapons.
    -Attack Range variable of AI.js is now properly taken into account for determining when to attack the player.
    -Fixed raycast calculation in DragRigidbody.cs so user won’t have to click outside and back in the running game window in the editor to drag rigidbodies.
    -Fixed rigidbodies keeping high drag values resulting in objects falling slowly.
    -Controls can now be easily set from the inspector in the FPSPlayer.cs script on the FPS Player object
    -Added swayAmountZoomed variable to WeaponBehavior.cs to control zoomed weapon sway which can be used for reducing the zoomed sway of scoped weapons.
    -Added swayAmountUnzoomed variable to WeaponBehavior.cs to allow customization of unzoomed sway amount for individual weapons.
    -Miscellaneous inspector visibility cleanup.​
     
  24. wheelbarrow

    wheelbarrow

    Joined:
    Sep 12, 2011
    Posts:
    132
    Hi guys, I picked up the asset yesterday, and am very happy with it, but I have a couple of questions: anything special to watch regarding installing the upgrade - i.e. will it import over the earlier version ok or do I have to remove the older version before bringing 1.1 in? I'm using Unity Pro version 4.1.1f4.

    Secondly, I am about to bring my enemies into my scene, and they have an apply damage script, but it looks for projectile object tag names to decide if it causes damage, and how much etc - I can't find any projectiles in this asset (apart from the ejection shells), so is it all raycast, and if so, whats the best way for me to tell my enemy it has been hit? The apply damage script is part of a larger ai script, so I can't really remove it without screwing everything else up. Thanks guys, and good job on the asset.
     
  25. Azuline-Studios

    Azuline-Studios

    Joined:
    Apr 5, 2013
    Posts:
    203
    Thanks wheelbarrow, glad you’re enjoying the Realistic FPS Prefab! As far as what to watch for when installing the update, it depends on what changes you’ve made to the scripts and objects in version 1.05. When you click the import button for the updated package in the asset store download manager, it will show you which files have changed in the update before giving you a chance to import them over your current files to upgrade the asset to 1.1.

    If you have changed many of those files, you might want to import the updated Realistic FPS Prefab 1.1 into an new empty project (keeping your modified project that uses 1.05) and then use a third party tool like WinMerge to view the differences between the version 1.1 scripts and your modified versions from 1.05. WinMerge will let you see where we made changes in the script for the update so you can decide how to add your code from the previous version’s script into the new version’s script.

    We mention the names of the scripts that were modified in the version notes to assist in tracking down where to plug in your changes in the new version, but if you have any requests, like a list of specific files that were changed in the new version, we can provide that for you as well.

    As for telling your enemy that it’s been hit, the WeaponBehavior.cs script has a function around line 740 called:

    Code (csharp):
    1.  
    2. void HitObject ( RaycastHit hit, Vector3 direction ){
    which is called when the raycast from the weapon hits an enemy collider. In that function physics force is applied to rigidbodies hit by the weapon’s raycast, and the enemy’s ApplyDamage function is called like this:

    Code (csharp):
    1.         //Call the ApplyDamage function in the hit object          
    2.         hit.collider.SendMessageUpwards("ApplyDamage", damage, SendMessageOptions.DontRequireReceiver);
    So from what you’ve described, it sounds like a raycast hit from the asset’s weapons should be able to call your AI script’s ApplyDamage function, if that’s the exact, case sensitive name of your function as well. If your AI script’s ApplyDamage function isn’t getting called, then you might want to look at the HitObject function in WeaponBehavior.cs and make sure that the function is using the same name in the SendMessageUpwards call, and that your script is attached to the same game object as the collider component that’s hit by the raycast.

    Please let us know if you still have questions on how to call the damage function of your AI script.
     
  26. kenlem

    kenlem

    Joined:
    Oct 16, 2008
    Posts:
    1,593
    How easy would it be to add input support for mobile devices? Are the input routines in one location or are they sprinkled through the code?
     
  27. wheelbarrow

    wheelbarrow

    Joined:
    Sep 12, 2011
    Posts:
    132
    Thanks, I got it figured out, and now the damage problem is sorted, but it leads to another one (sorry) : I have my enemies on the NPCs layer, which is supposed to be masked from the bullets according to weapon behaviour cs, but I have bullet holes appearing on the box collider on my npc. The only difference I see between your robots in your demo scene, and my npc, is you use a character controller, and I use a rigidbody, which my ai uses to move the npc's, and a box collider (I can't use a cc, it screws up the ai ). How do I get rid of the bullet holes if the npc is already on the bullet mask layer? Thanks, and sorry to be a bother.
     
  28. Azuline-Studios

    Azuline-Studios

    Joined:
    Apr 5, 2013
    Posts:
    203
    In version 1.1, the input key assignments are all centralized in the FPSPlayer.cs script, but the actual Input.GetKey calls are located at places in the other scripts where they are needed as part of other behaviors. If you were going to add input for mobile devices, I imagine it would be as simple as swapping the input key assignments in FPSPlayer.cs for the button/virtual pad controls of your mobile input system.

    If you needed an input call other than Input.GetKey, then you might have to go through the scripts and swap them out, but it shouldn't be too complicated if you right click on an Input.GetKey or Input.GetKeyDown reference in MonoDevelop and click on the Find References option to bring up a window of all the Input.GetKey calls used in the asset. Then it's only a matter of clicking on the entries in the Search Results window and MonoDevelop should take you right to them where you could paste over your own input calls.

    There are about 40 Input.GetKey calls and 15 Input.GetKeyDown calls in the scripts. We can offer advice and support if you need help changing the input method used in the project.

    No problem wheelbarrow! The bullet mask layer is only for telling the weapon raycast to check that object for a collision. This asset uses tags to determine whether or not to leave hit marks on an object. Have you tried setting the game object tag of your enemies to NoHitMark? That tells the WeaponBehavior.cs script to not put hit marks on that object. If you need your NPC to have a different tag than NoHitMark, then you can add a check for MyExampleTag in the BulletMarks function in the WeaponBehavior.cs script around line 1004 like this:

    Code (csharp):
    1.     void BulletMarks ( RaycastHit hit  ){
    2.         if(hit.collider//check only objects with colliders attatched to prevent null reference error
    3.          hit.collider.gameObject.layer != 9//don't leave marks on ragdolls
    4.          hit.collider.gameObject.tag != "NoHitMark"//don't leave marks on active NPCs or objects with NoHitMark or PickUp tag
    5.          hit.collider.gameObject.tag != "PickUp"
    6.          hit.collider.gameObject.tag != "MyExampleTag"){
    Hope that helps you with your NPC/BulletMark problem.
     
    Last edited: Apr 12, 2013
  29. Unicron

    Unicron

    Joined:
    Sep 28, 2011
    Posts:
    191
    Can the pickup system be modified so that instead of picking up the item right away you can set it to give an option when clicked to pickup (put in inventory), use, equip, destroy, etc.

    Also can the drag object be modified so that you don't have to hold the z key and instead press once to pickup and drag and press again to drop?
     
  30. Azuline-Studios

    Azuline-Studios

    Joined:
    Apr 5, 2013
    Posts:
    203
    Hi Unicron, the pickup system can be modified however you see fit. We've had a few requests to add an option for a system like the one you described where the player taps the use button once to pick up the object, and again to drop the object. So I will be looking into adding this for a future update.

    The current system works by adding a spring joint on the object where the crosshair is currently positioned. This allows you to grab the corner of a physics object and spin it relative to the rest of the object. For the method like you described, I'm considering just modifying the position of the object itself. The DragRigidbody.cs script would also need a simple toggle behavior added to it to handle the button presses.

    Also, in the next update, the option to have pickups stay after being used (instead of disappearing) will be added to allow for the creation of resupply rooms and such.

    This thread will be updated as progress is made on new features, but feel free to ask for advice if you want to try implementing the system sooner on your own.
     
    Last edited: Apr 13, 2013
  31. kerryenfinger

    kerryenfinger

    Joined:
    Jan 22, 2013
    Posts:
    14
    Bought the Realistic FPS Prefab last night. Excellent resource!!! Do you have any idea when version 1.1 will go live on the Asset Store? It still shows version 1.05.
     
  32. Azuline-Studios

    Azuline-Studios

    Joined:
    Apr 5, 2013
    Posts:
    203
    Thanks kerryenfinger, Version 1.1 should be going live in a few days. It's still going through the Unity review process. We're glad you're enjoying the asset!
     
  33. hellraizerhhh

    hellraizerhhh

    Joined:
    May 26, 2010
    Posts:
    619
    Guns need a bit of work to feel realistic. Currently the manipulation of the weapons is really weak. The character barely moves his hand and the shotgun loads. Realistically it would take much more energy and a further pull to eject and load a new shell. The MP5 cocking handle is manipulated so softly it stands out as nowhere near realistic. You have to hit the charging handle down for it to slide forward with force. As far as the AK, you have the character ejecting the magazine and hes not even using the magazine release, how did he take it out? The Katana was the worst offender. Hes just stand there and swings from the idle position. There is no transfer of energy or momentum. If you wield a sword you will notice that you would have to pull it back to build the needed energy to strike down (in animation this is anticipation). You would then strike down and have the energy transfer through and continue for a bit as the momentum stops (this is called overlap and follow through)

    Ultimately I'm just trying to say that the guns and sword are working nowhere as they would in real life. Once they are tweaked it will feel much nicer
     
    Last edited: Apr 14, 2013
  34. salad__fingers

    salad__fingers

    Joined:
    Aug 11, 2012
    Posts:
    41
    How do you make it to where you spawn with a gun?
    Cheers.


    EDIT
    Nevermind, I found it.
    For anyone else with this, simply tick "Have Weapon" on the weapon game object. Then, go to FPS Weapons, and change First Weapon to the number of the weapon you chose. For example if you want to spawn with an AK47, click AK47, tick Have Weapon, go to FPS Weapons, and then type in 5 for first weapons.
     
    Last edited: Apr 14, 2013
  35. Azuline-Studios

    Azuline-Studios

    Joined:
    Apr 5, 2013
    Posts:
    203
    hellraizerhh, we'll definitely consider your feedback on the weapon animations when we get the chance. Thank you.

    Glad you were able to figure this out salad__fingers! We made the First Weapon variable so you can choose which weapon to spawn with and it is also a variable you would want to store in memory or a save game file if the player was changing scenes/areas and you wanted them to keep the same weapon they had equipped from the previous map. Let us know if you have any more questions.


    Some notes on our recent progress improving the asset:

    Pausing the game

    We've recently incorporated a fix to our code that allows the game to be paused by setting Time.timeScale to 0 and back to a positive value. 1.1 and earlier versions don't have this fix incorporated yet and will display NaN errors from the Mathf.SmoothDamp functions when changing the value of Time.timeScale to zero and back to a positive value. Here are the modifications that we made to our code to allow pausing by changing the value of Time.timeScale.

    What's required is to enclose the actions of a few scripts in if(Time.timeScale > 0){ checks. Specifically line 54 of SmoothMouseLook.cs should be changed to:

    Code (csharp):
    The Update() code of Ironsights.cs starting around line 115 should be enclosed in a if(Time.timeScale > 0){ check.

    The Update() code of Gunsway.cs starting around line 58 should be enclosed in a if(Time.timeScale > 0){ check.

    And both the Update() and FixedUpdate() code of WeaponBehavior.cs should be enclosed in if(Time.timeScale > 0){ checks.

    This should allow you to pause the game by setting Time.timeScale to 0. If you're having trouble, feel free to contact us and we can send you the fixed scripts.



    Shotgun Reloading

    The shotgun reloading method (non magazine reloading) used in our asset is a bit more complex than the technique used for reloading by magazine. We're going to be updating our documentation in a future update to help explain how the weapon animations work for shotguns or other weapons where you want the player to reload them one bullet/shell at a time. But for now, here is a description of how our shotgun reloading animations work:

    Shotgun reloading takes some extra programming, but we tried to make it to be as simple as possible in the asset. Our demo shotgun has one shooting animation and one continuous reloading animation where hand goes from neutral, to loading a shell, back to neutral, and then pumping the shotgun.

    We tell unity that the first frame of the reload animation starts when the hand is already loading the shell. So the weaponMesh.animation.CrossFade() call of the script is actually filling in/interpolating the frames from when the hand starts to move toward the shell loading port from the original position.

    Then Unity just loops the reloading animation until the last shell is reloaded, where the whole last part of the animation (pumping the shotgun) is allowed to play. We also define a Neutral animation of the hand going from the reload port back to neutral (without pumping) for when shotgun reloading is interrupted and not allowed to finish by another action like sprinting or shooting.

    So if your shotgun reload animation has reload start, loading a bullet/shell, and finish reload animations in that sequence in the model, you can set the Reload animation's start frame in the model's import settings to the first frame of the loading a bullet/shell animation and set the last frame of the Reload animation to the last frame of your finish reload animation including the shotgun pump/chambering animation if your animations have one.

    You would then want to define the Neutral animation to be the frames of your reload animation where the hand is returning to the firing position after inserting the shell so reload animation interruptions will be smooth and continuous. Then you could set the Ready animation frame range to be the frames where the hands pump the shotgun.

    The weaponMesh.animation["Reload"].speed = 0.7f; line of code in WeaponBehavior.cs around line 929 determines the animation speed of how quickly the bullet loading part of the reloading animation is played when it's being looped during reloading. So 0.7f can be changed to whatever looks smoothest for your reload animation (we slowed it down to 0.7 from 1.0). This will be added as a customizable variable per-gun in a future update.
     
  36. OneShotGG

    OneShotGG

    Joined:
    Nov 16, 2012
    Posts:
    225
    Just purchased the pack and I really think it is top quality (anxiously awaiting the new patch though :p ).

    The question I have pertains to animation. What program did you use to animate the arms and guns? I need to do some custom animations (reloading different locations like c96, lugar, etc , and revolver animations) and when I loaded the m1911anim.fbx file into 3dsmax the hands were all messed up (the animations went though though).
     
  37. Azuline-Studios

    Azuline-Studios

    Joined:
    Apr 5, 2013
    Posts:
    203
    Thanks OneShotGG! The program we used to animate the arms and guns is Maya. Importing the .FBX into Maya should maintain the object hierarchies and bone weights/skin cluster output for the arm bones and allow you to see how the animations work. If you have any other questions, please let us know.




    In other news, yes, we know our asset store link is down. We hope to have it back up soon.

    Sorry for the inconvenience,

    [video=youtube_share;kvX7TFA4jV0]http://youtu.be/kvX7TFA4jV0​
     
    Last edited: Apr 17, 2013
  38. Dari

    Dari

    Joined:
    Mar 25, 2013
    Posts:
    130
    Yes, I've tried to download the new 1.1 version, but link is down :( why, what happend? :eek:
    I hope it will be back because I love that asset, I'll stand by. When will it be back, do you know maybe?

    Oh, almost forgot: AK47 and MP5 won't shoot? :S (no animation, no projectile and no bullet marks of course)
    It says some errors in script WeaponBehaviour: Line: 183, 228 and 685
    Some animations problems as I saw

    Please help me!
     
    Last edited: Apr 17, 2013
  39. OneShotGG

    OneShotGG

    Joined:
    Nov 16, 2012
    Posts:
    225
    Yeah, I figured it out :p. I actually have a Luger model in the game now and working with tweaked animations (I am not an animator but I know enough to be dangerous...lol)

    I'll take a youtube of how it looks once I get the texture done the way I like it. (PS yalls documentation is very good, had no problems once I started following that ;) )
     
  40. Dari

    Dari

    Joined:
    Mar 25, 2013
    Posts:
    130
    Heh, any idea how to fix it? :(
    I need those machine guns! (love them) :D
     
  41. Azuline-Studios

    Azuline-Studios

    Joined:
    Apr 5, 2013
    Posts:
    203
    Great job OneShotGG. We did try to make the documentation as helpful as possible. Glad you got everything working! Looking forward to your video :)

    Sorry for the inconvenience Dari, the link should be back up soon.

    For the weapon errors, can you give us some additional details about what's happening. First of all, are you you trying to run the demo scene, or a new scene? If you are trying to run the demo scene, have you changed anything from the default configuration of the FPS Prefab? From the errors you were mentioning, it sounds like the weapon object is having problems finding its parent sprinting animation, which might mean that the weapon object is out of the hierarchy that it needs to communicate to the rest of the prefab.

    We've done a lot of testing and the FPS Prefab should work just by dragging it into a scene with its default settings, but if the weapon parent/child hierarchies are misconfigured, then you can click on the !!!FPS Main object in the Hierarchy window and then click on the middle "revert" button on the Prefab row in the inspector. This will revert any changes that have been made to the prefab to default, unless you clicked the "apply" button at some point and stored a state other than the default. In that case, you'd want to restore the backup "!!!FPS Player Main Original" prefab from the !Realistic FPS Prefab Files/!Objects folder. If you have done a lot of work, you might want to save your progress in a separate scene before trying this.

    You might also want to check out the documentation if you haven't already to get a better idea of how the gameobjects that make up the FPS Prefab communicate with the scripts. If you are still having problems, would you please describe again step-by-step what you are experiencing so we can track down the cause? Thank you.
     
  42. Dari

    Dari

    Joined:
    Mar 25, 2013
    Posts:
    130
    1. I'm trying demo and my scene and it's still the same. (won't work, the guns)
    2. I didn't change anything in demo scene, still won't work.
    3. When I play, other guns are working fine expect these two (AK47 and MP5)
    4. When I collect the weapon AK47/MP5 then in debug it says: NullReferenceException (it happens in gameplay)
    5. When the game is paused/quit in debug it says following errors:

    WHEN I COLLECT THE WEAPON IT SAYS THESE TWO ERRORS:
    NullReferenceException
    WeaponBehavior.Start () (at Assets/!Realistic FPS Prefab Files/Scripts/Weapons/WeaponBehavior.cs:183)

    NullReferenceException
    WeaponBehavior.OnEnable () (at Assets/!Realistic FPS Prefab Files/Scripts/Weapons/WeaponBehavior.cs:228)
    UnityEngine.GameObject:SetActive(Boolean)
    <SelectWeapon>c__Iterator6:MoveNext() (at Assets/!Realistic FPS Prefab Files/Scripts/Weapons/PlayerWeapons.cs:255)

    BUT WHEN I SHOOT THE BULLET IT SAYS THIS ERROR:
    NullReferenceException
    WeaponBehavior+<FireOneShot>c__Iterator8.MoveNext () (at Assets/!Realistic FPS Prefab Files/Scripts/Weapons/WeaponBehavior.cs:685)
    UnityEngine.MonoBehaviour:StartCoroutine(String)
    WeaponBehavior:Fire() (at Assets/!Realistic FPS Prefab Files/Scripts/Weapons/WeaponBehavior.cs:649)
    WeaponBehavior:Update() (at Assets/!Realistic FPS Prefab Files/Scripts/Weapons/WeaponBehavior.cs:551)

    That's all, I've also tried to revert the !!!FPS Player Main and didn't worked.
    Thanks for helping me, wish you the best luck!

    I'm really sorry if I am asking too much, it's because I don't know much about scripting, that's the hardest for me.
    I'm only 12 years old...

    Please answer as soon as possible, thank you.
     
    Last edited: Apr 19, 2013
  43. Azuline-Studios

    Azuline-Studios

    Joined:
    Apr 5, 2013
    Posts:
    203
    No problem Dari, thanks for the detailed report. The first clue is that the other guns are working fine except the AK47 and MP5. This leads me to believe that something about the default setup involving those guns has changed, not downloaded correctly, or not initialized as it's designed to.

    The errors in WeaponBehavior.cs all seem to be tied to setting the animation speeds of the view weapon mesh, which happens when you pick up or select the weapon (ready animation speed) and when you fire the weapon (fire animation speed) like you described. The fact that you're getting null reference errors might point to the fact that the WeaponBehavior.cs instances for those weapons don't have their WeaponMesh value set to the weapon model object underneath them in the hierarchy.

    The Animation component of the MP5_Anim and AK47_Anim objects should also have 3 entries; Fire, Reload, and Ready, that use the imported animations from the _Anim meshes.


    The first thing I'd suggest is to get version 1.6 of our asset and make sure everything has downloaded and unpacked correctly and then try out the demo scene without modifying any settings.

    If you still get the errors, could you please take a screen shot of the scene when it's running so the hierarchy window is visible with the !!!FPS Main/FPS Weapons/MP5 object selected so the top of the MP5's WeaponBehavior.cs script instance is visible in the inspector window? That should let me know if your FPS Weapon hierarchy is intact and if the WeaponBehavior.cs instance is configured correctly.

    We're sorry you're running into problems. Thanks for your patience!
     
    Last edited: Apr 20, 2013
  44. lod3

    lod3

    Joined:
    Mar 21, 2012
    Posts:
    514
    Hi Azuline,

    Noticed it hasn't been asked yet, but was wondering if there was any way to use your climbing, gun and pickup code with the Ultimate FPS Camera, or if it's just too tied to your own camera? My background is design/art, so coding knowledge is extremely limited.

    If it's something that would require you to have a copy of Ultimate FPS Camera to accomplish, I don't mind sending you the funds to purchase it through PayPal, if it will result in something usable, or at the very least result in a tutorial everyone can follow to do this.

    Please advise.
     
  45. OneShotGG

    OneShotGG

    Joined:
    Nov 16, 2012
    Posts:
    225
    Quick couple of questions...

    1. What would be the best way to limit the player to two weapons (like COD Zombies).

    2. I have a magic casting system (Js) that I have integrated into your prefab. I need to be able to call the current weapon in order to play the spell casting animation. I have look through your scripts and cannot find a "current weapon" variable or class. How are yall calling the current weapon?
     
  46. Dari

    Dari

    Joined:
    Mar 25, 2013
    Posts:
    130
    Still not working. I've downloaded the new 1.16 version but these two guns works same.

    ERRORS:


    When I collect the weapon:

    NullReferenceException
    WeaponBehavior.Start () (at Assets/!Realistic FPS Prefab Files/Scripts/Weapons/WeaponBehavior.cs:186)

    NullReferenceException
    WeaponBehavior.OnEnable () (at Assets/!Realistic FPS Prefab Files/Scripts/Weapons/WeaponBehavior.cs:231)
    UnityEngine.GameObject:SetActive(Boolean)
    <SelectWeapon>c__Iterator6:MoveNext() (at Assets/!Realistic FPS Prefab Files/Scripts/Weapons/PlayerWeapons.cs:259)

    When I shoot with them:

    NullReferenceException
    WeaponBehavior+<FireOneShot>c__Iterator8.MoveNext () (at Assets/!Realistic FPS Prefab Files/Scripts/Weapons/WeaponBehavior.cs:694)
    UnityEngine.MonoBehaviour:StartCoroutine(String)
    WeaponBehavior:Fire() (at Assets/!Realistic FPS Prefab Files/Scripts/Weapons/WeaponBehavior.cs:658)
    WeaponBehavior:Update() (at Assets/!Realistic FPS Prefab Files/Scripts/Weapons/WeaponBehavior.cs:559)


    SCREENSHOTS:

    Screenshot 1:
    $UnityFPS03.JPG

    Screenshot 2:
    $UnityFPS205.JPG

    Screenshot 3: (Gameplay mode)
    $UnityFPSgame04.JPG

    Maybe I should make a video? Thanks for your patience!
     

    Attached Files:

    Last edited: Apr 21, 2013
  47. lebid

    lebid

    Joined:
    Nov 17, 2012
    Posts:
    30
    hummm .... No error with version 1.05 and 1.16 for me
     
  48. Dari

    Dari

    Joined:
    Mar 25, 2013
    Posts:
    130
    MP5 and AK47 are working good?
    I would say that something isn't working good with my Unity or something like that, I hope that Asset is very nice and working fine for others. :)
     
  49. Azuline-Studios

    Azuline-Studios

    Joined:
    Apr 5, 2013
    Posts:
    203
    There was some discussion between us and TheRealFuzz about porting our climbing code in this post. Our movement and weapon scripts are pretty integrated into our asset, but with some study of both code bases, I'm sure something could be achieved by people who own both assets.

    As far as making elements of the two assets interchangeable out of the box, we can see how that would be great for you guys, but it really starts to go into a grey area license-wise because these are copyrighted commercial products being sold on their own merits. We don't have the rights to publish or sell copyrighted code from other projects and vice versa, so it would be up to the customers who have purchased both assets as to what they do individually with them.

    What we can do is provide information and support on what parts of our code can interface with other scripts. We just assisted a customer in changing our Input.GetKey calls to mobile touch button inputs using the 2D Toolkit, for example. I hope this answers your question.


    Great questions OneShotGG. To limit the player to two weapons, you could create a variable like maxWeapons and a check for this variable in the SelectWeapon() function in PlayerWeapons.cs that doesn't allow the player to pick up new weapons if their totalWeapons is greater than the maxWeapons amount already. To track the totalWeapons amount, you could write a for statement in PlayerWeapons.cs that iterates through all weapon objects in the WeaponOrder array to see if the haveWeapon value of their WeaponBehavior.cs instance is set to true, and if so, add it to the totalWeapons var. There would also need to be an initialization check in the Start() code so totalWeapons doesn't exceed maxWeapons. That's not a perfect explanation, but that describes how I'd approach it.

    The current weapon number is stored in the childNum variable of PlayerWeapons.cs. We should probably change the name to something more obvious like currentWeapon. The value of childNum corresponds to the current weapon's array index number in the WeaponOrder array. childNum is a public var, but it's hidden from the inspector because it's handled at runtime by PlayerWeapons.cs

    We will be adding droppable weapons soon and it would make sense for us to add the max weapons feature at the same time since it involves changing PlayerWeapons.cs. If you have any problems implementing it on your own, let us know and we'll help you.


    Well, from what I can see in the screenshots, it looks like the FPS Prefab is set up correctly. The errors you are having are pointing to the animation speed calls. The first thing I would suggest doing is commenting out or typing "//" at the beginning of the lines 694 and 186 which have the weaponMesh.animation["Fire"].speed = fireAnimSpeed; calls in WeaponBehavior.cs and then test the scene to determine if the errors stop, or if they occur on different lines.

    If the errors do stop, then you can leave those lines commented out. If not, could you post the errors that happen after the lines are commented out?

    You also can read the tutorial on adding new weapons and create a new weapon by duplicating a weapon object, dragging a new instance of the AK47_Anim or MP5_Anim model from the library over the duplicated object so it becomes a child of the weapon object, along with the other steps from the tutorial. If the errors happen on your new weapon, try switching out the MP5_Anim or AK47_Anim model with an _Anim model from one of the other working weapons and see if the errors still happen.


    Thanks lebid, we're trying to recreate the problem Dari's describing without any luck. Hopefully what we suggested above will give us some more info!
     
    Last edited: Apr 21, 2013
  50. Dari

    Dari

    Joined:
    Mar 25, 2013
    Posts:
    130
    It shoots but no animation :D

    When I collect the weapon:

    NullReferenceException
    WeaponBehavior.Start () (at Assets/!Realistic FPS Prefab Files/Scripts/Weapons/WeaponBehavior.cs:187)

    NullReferenceException
    WeaponBehavior.OnEnable () (at Assets/!Realistic FPS Prefab Files/Scripts/Weapons/WeaponBehavior.cs:231)
    UnityEngine.GameObject:SetActive(Boolean)
    <SelectWeapon>c__Iterator6:MoveNext() (at Assets/!Realistic FPS Prefab Files/Scripts/Weapons/PlayerWeapons.cs:259)

    When I shoot:

    The animation state Fire could not be played because it couldn't be found!
    Please attach an animation clip with the name 'Fire' or call this function only for existing animations.
    UnityEngine.Animation:CrossFade(String, Single, PlayMode)
    <FireOneShot>c__Iterator8:MoveNext() (at Assets/!Realistic FPS Prefab Files/Scripts/Weapons/WeaponBehavior.cs:695)
    UnityEngine.MonoBehaviour:StartCoroutine(String)
    WeaponBehavior:Fire() (at Assets/!Realistic FPS Prefab Files/Scripts/Weapons/WeaponBehavior.cs:658)
    WeaponBehavior:Update() (at Assets/!Realistic FPS Prefab Files/Scripts/Weapons/WeaponBehavior.cs:559)

    It says some errors when I reload the guns:

    NullReferenceException
    WeaponBehavior.FixedUpdate () (at Assets/!Realistic FPS Prefab Files/Scripts/Weapons/WeaponBehavior.cs:347)

    NullReferenceException
    WeaponBehavior+<Reload>c__Iterator9.MoveNext () (at Assets/!Realistic FPS Prefab Files/Scripts/Weapons/WeaponBehavior.cs:860)
    UnityEngine.MonoBehaviour:StartCoroutine(String)
    WeaponBehavior:FixedUpdate() (at Assets/!Realistic FPS Prefab Files/Scripts/Weapons/WeaponBehavior.cs:343)

    By the way, hadn't got too much time so I didn't tried the second example to fix the weapons (one where I have to recreate the weapons).

    Sorry about that.
     
    Last edited: Apr 21, 2013