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. RealAspireGames

    RealAspireGames

    Joined:
    Dec 24, 2013
    Posts:
    265
    Is multiplayer just impossible to create for this asset at the moment. I mean I have even went as far as purchasing bolt networking in hopes that multiplayer with this asset would work but still nothing...
     
  2. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,657
    I'll give Bolt a try this weekend and let you know if I can get it working. If so, I'll just share the procedure instead of putting together a separate networking product for RFPS.
     
    RealAspireGames and Eyehawk like this.
  3. SuperNewbee

    SuperNewbee

    Joined:
    Jun 2, 2012
    Posts:
    195
    Bolt with RFPS would be awesome. I purchased bolt a while ago but never tried to get it to work with RFPS because it seemed like an intimidating procedure.
     
  4. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,657
    @godofwarfare115 and @SuperNewbee - How do you propose handling visibility of other players? An RFPS player is an invisible capsule. As a quick proof of concept, I added a plain gray capsule mesh to the player prefab and set up extremely rudimentary multiplayer with Bolt -- just running around and looking at each other. I didn't hook up weapons yet. I'll probably set up a body for other players using a Mecanim humanoid rig unless you have other ideas.
     
  5. SuperNewbee

    SuperNewbee

    Joined:
    Jun 2, 2012
    Posts:
    195
    I was going to wait until player body was added to RFPS by Azuline. I never really tried to make it work myself. (I would rather just buy your Bolt/RFPS addon :))
     
  6. poison77

    poison77

    Joined:
    Dec 24, 2013
    Posts:
    40
    Thank you TonyLi :)
     
  7. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,657
    We can't be sure when player bodies will be added, so I'll go ahead this weekend with a free tutorial on getting RFPS working with Bolt, using a simple Mecanim humanoid for other players.
     
  8. RealAspireGames

    RealAspireGames

    Joined:
    Dec 24, 2013
    Posts:
    265
    I just purchased another asset called "Complete Soldier pack" It includes full animations and player models... I was just going to use those for the multiplayer if someone does get it working! :D
     
  9. RealAspireGames

    RealAspireGames

    Joined:
    Dec 24, 2013
    Posts:
    265
    Has anyone figured it out yet I am willing to pay money to get everything from killing each other with this asset to correct objects in the server!
     
  10. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,657
    If you're talking about multiplayer, I'm working on it this weekend. I don't know what will come of it, but if I get everything working I'll at least post the steps here.
     
  11. RealAspireGames

    RealAspireGames

    Joined:
    Dec 24, 2013
    Posts:
    265
    Alright I wish you luck if you actually get it working and post a step by step instructions you would really help everyone who has RFPS and Bolt Networking out A TON!!!!
    Thank you
     
  12. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,657
    EDIT: Updated 2016-12-14 for RFPS 1.23 and Bolt 0.4.3.17.
    EDIT: Updated 2016-02-14 for RFPS 1.22 and Bolt 0.4.3.12.


    Okay, here's what I did to get RFPS working with Bolt. I didn't implement third-person bodies, but I left stubs where someone could. I'm not sure what I'm going to do with this, if anything. I was just curious to see how it would work out. So please run with it and share whatever you add.

    Be warned that it's still a lot of work, but I think most of the hard part of the core gameplay is done. Bolt doesn't have a lobby or matchmaking system, so you'll have to add that yourself, too.

    First, since RFPS uses rigidbodies, it has to be a non-authoritative server. That is, the player rigidbody (physics simulation) lives on the player's client, not on the server. If you're worried about cheating, you'll have to implement other anti-cheat measures (google it if you need to).

    Start by importing RFPS and Bolt.

    Then delete the assets/bolt/samples folder.


    Bolt Assets
    In the "Bolt Assets" window, create:
    • States:
      • PlayerState - with these properties: (rename existing PlayerState to something like PlayerState2)
        • FPSPlayerTransform (transform)
    • Objects:
      • Player
    • Events
      • DamageEvent - with these properties:
        • Player (entity)
        • ID (integer)
        • Damage (integer)
        • AttackDir (vector)
        • AttackPos (vector)
      • DestroyEvent - with these properties:
        • ID (integer)
      • EquipEvent - with these properties:
        • Player (entity)
        • WeaponNumber (integer)
      • FireEvent - with these properties:
        • Player (entity)
        • WeaponNumber (integer)
        • Direction (vector)
    Then click the green down arrow button, or select Assets > Bolt Engine > Compile Assembly.


    Then you have to make some changes to RFPS scripts. I tried to keep these to a minimum.

    RFPS Script Changes

    In WeaponPickup.cs:77 (line 42 in RFPS 1.22, line 38 in RFPS 1.21), add this line:
    Code (csharp):
    1.         Start(); //[TL]
    (I marked all my code changes with "//[TL]".) This is the first line in the PickUpItem() method. WeaponPickup sets up some references in Start(), but they're not valid in a networked game. A quick fix was to call Start() again at the beginning of the PickUpItem() method.


    In PlayerWeapons.cs, add this code:
    Line 6:
    Code (csharp):
    1.     public class SelectedWeaponEventArgs : System.EventArgs { public int weaponNumber; public SelectedWeaponEventArgs(int i) {weaponNumber=i;} } //[TL]
    2.     public event System.EventHandler<SelectedWeaponEventArgs> SelectedWeapon = delegate{}; //[TL]
    This is right after the class name definition.

    Line 475 (line 378 in RFPS 1.22, line 375 in RFPS 1.21):
    Code (csharp):
    1.         SelectedWeapon(this, new SelectedWeaponEventArgs(index)); //[TL]
    This is in the SelectWeapon() method. It adds an event. Whenever the local player equips a weapon, it invokes this event. Other scripts (we'll get to it in a bit) will hook into this event.


    In WeaponBehavior.cs, add this code:
    Line 9 (line 7 in RFPS 1.21-1.22):
    Code (csharp):
    1.     public class FiredWeaponEventArgs : System.EventArgs { public int weaponNumber; public Vector3 direction; public FiredWeaponEventArgs(int i, Vector3 d) {weaponNumber=i; direction=d;} } //[TL]
    2.     public event System.EventHandler<FiredWeaponEventArgs> FiredWeapon = delegate{}; //[TL]
    3.     public class DamagedTargetEventArgs : System.EventArgs { public GameObject target; public int damage; public Vector3 attackDir; public Vector3 attackPos; public DamagedTargetEventArgs(GameObject t, int d, Vector3 dir, Vector3 pos) {target=t; damage=d; attackDir=dir; attackPos=pos;} } //[TL]
    4.     public event System.EventHandler<DamagedTargetEventArgs> DamagedTarget = delegate{}; //[TL]
    Line 2206 (line 1052 in RFPS 1.22, line 1112 in RFPS 1.21):
    Code (csharp):
    1.         //[TL]
    2.         if ((hit.collider.GetComponentInParent<BoltEntity>() != null) || (hit.collider.GetComponentInParent<BoltAwareDamageable>() != null)) {
    3.             DamagedTarget(this, new DamagedTargetEventArgs(hit.collider.gameObject, damage, direction, mainCamTransform.position));
    4.         } else {
    5.             (put the switch statement in here)
    6.         }
    This is in the HitObject() method. At adds multiplayer events (firing a weapon and damaging a target).

    These scripts won't actually compile successfully until you get past the next section.


    More Scripts!
    Download these scripts: Bolt_RFPS_Integration_Scripts_2015-02-01.unitypackage. The package contains:
    • BoltPlayer.cs: Interfaces between Bolt and RFPS.
    • BoltPlayerCallbacks.cs: Handles player spawning. (NOTE: Currently spawns in random position!)
    • GlobalCallbacks.cs: Handles equip, fire, damage, and destroy events.
    • BoltAwareDamageable.cs: Syncs damage across the network.
    • BoltAwareDestructible.cs: Syncs destruction of local objects across the network.
    • TimedActivate.cs: Simple helper script to activate GameObjects after a delay (to allow the player to spawn first).
    For RFPS 1.23, edit BoltAwareDamageable.cs. Change line 41 to:
    Code (csharp):
    1. target.GetComponent<CharacterDamage>().ApplyDamage(damage, attackDir, attackPos, null, true, false);
    For RFPS 1.22, edit BoltAwareDamageable.cs. Change line 41 to:
    Code (csharp):
    1. target.GetComponent<CharacterDamage>().ApplyDamage(damage, attackDir, attackPos, null, true);
    Changes for RFPS 1.23:
    • BoltPlayer.cs:60: Comment out the line with "CameraKick" by adding // to the front.
    • BoltPlayer.cs:80: Comment out the line with "ammoGuiObj".

    Then click Bolt's green down arrow button again.

    You may still need to fiddle around with the scripts a bit. If Unity reports a compiler error, temporarily comment out the offending lines until you can get it to compile. Then uncomment them. Once Unity get a first clean compile of Bolt and updates the APIs for the version of Unity you're using, it should continue to compile correctly from then on.


    Setup Player Prefab
    1. Add !!!FPS Player Main to a scene.
    2. Rename it to Player.
    3. Add a BoltEntity component.
    4. Create a Resources folder, and drag Player into the Resources folder.
    5. Click the green down arrow button again. This should resolve any red errors in the Player's BoltEntity.
    6. Set the BoltEntity's State to IPlayerState.
    7. Add a BoltPlayer component (from the package linked above).
    8. Remove FPSCamera's WorldRecenter script. (RFPS 1.21-1.22: On !!!FPS Player's WorldRecenter script, untick Remove Prefab Root.)
    9. Add a child GameObject to !!!FPS Player.
      - Name it Proxy. This will be the proxy third-person body for other players.
      - Set Proxy's layer to NPCs.
      - Add a CapsuleCollider and Rigidbody (tick IsKinematic) so the local player can hit it.
      - Assign Proxy to Player's BoltPlayer > Proxy Body field.
    10. Click Apply to update the prefab. Then remove Player from the scene, as well as any other cameras. (If you started with a default new scene, Unity added a generic MainCamera.)

    Setup Objects

    Pickups: You must add a BoltAwareDestructible script to each pickup. Set a unique ID number for each one. When a player picks up a pickup, it sends a DestroyEvent over the network with this ID number. The other clients will find the same pickup and destroy it to keep the world in sync.

    Destructibles: Add a BoltAwareDestructible and a BoltAwareDamageable to destructibles like explosive barrels. This keeps damage (hit points) in sync as well as syncing when the object blows up. Now that I think about it, as confusing as the name is, you probably don't need to add a BoltAwareDestructible. When the destructible takes enough damage on each client (via BoltAwareDamageable) it will destroy itself.

    NPCs: Add a BoltAwareDamageable.


    Third-Person Body
    At the bottom of BoltPlayer.cs, fill in EquipWeaponOnProxy() and FireWeaponOnProxy(). These should play animations, etc. You'll also want to play idle or movement animations based on whether the player is moving or not (you can compare transform.position in Update).
     
    Last edited: Dec 18, 2016
  13. RealAspireGames

    RealAspireGames

    Joined:
    Dec 24, 2013
    Posts:
    265
    THANK YOU SO MUCH! At least the buyers or RFPS and who have bolt can do something with multiplayer now! going to be working on this all week this week! Thanks agian!
     
    Defcon44 likes this.
  14. Defcon44

    Defcon44

    Joined:
    Aug 19, 2013
    Posts:
    400
    Whoa :eek:

    Great jobs !!!

    thanck you so much ! :D

    But i can't download the " Bolt_RFPS_Integration_Scripts_2015-01-19.unitypackage "

    after clic on it i have this page :

     
  15. thenamesace

    thenamesace

    Joined:
    Jan 25, 2014
    Posts:
    157
  16. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,657
    Right-click on the link and select Save As... Or copy the scripts from here:

    BoltPlayer.cs:
    Code (csharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class BoltPlayer : Bolt.EntityBehaviour<IPlayerState> {
    5.  
    6.    public GameObject proxyBody;
    7.  
    8.    public bool isControlled { get; set; }
    9.  
    10.    private Transform fpsCamera = null;
    11.    private Transform fpsPlayer = null;
    12.    private Transform fpsWeapons = null;
    13.  
    14.    private void Awake() {
    15.      isControlled = false;
    16.      fpsCamera = transform.FindChild("!!!FPS Camera");
    17.      fpsPlayer = transform.FindChild("!!!FPS Player");
    18.      fpsWeapons = transform.FindChild("!!!FPS Weapons");
    19.      if (fpsCamera == null || fpsPlayer == null || fpsWeapons == null) {
    20.        enabled = false;
    21.      }
    22.    }
    23.  
    24.    private void Update() {
    25.      if (!isControlled) {
    26.        fpsCamera.transform.position = fpsPlayer.transform.position;
    27.        fpsCamera.transform.rotation = fpsPlayer.transform.rotation;
    28.        fpsWeapons.transform.position = fpsPlayer.transform.position;
    29.        fpsWeapons.transform.rotation = fpsPlayer.transform.rotation;
    30.      }
    31.    }
    32.  
    33.    public override void Attached() {
    34.      Debug.Log(gameObject.GetInstanceID() + ": Player syncing transform");
    35.      state.FPSPlayerTransform.SetTransforms(GetComponentInChildren<FPSPlayer>().transform);
    36.      GetComponentInChildren<FPSPlayer>().rigidbody.isKinematic = !entity.isOwner;
    37.      Invoke("CheckControl", 0.1f);
    38.    }
    39.  
    40.    private void CheckControl() {
    41.      Debug.Log(gameObject.GetInstanceID() + ": CheckControl, isPlayer=" + isControlled);
    42.      var isProxy = !isControlled;
    43.      fpsPlayer.rigidbody.isKinematic = isProxy;
    44.      if (proxyBody != null) {
    45.        proxyBody.SetActive(isProxy);
    46.      }
    47.      if (fpsCamera != null) {
    48.        fpsCamera.GetComponent<SmoothMouseLook>().enabled = isControlled;
    49.        fpsCamera.GetComponentInChildren<Camera>().enabled = isControlled;
    50.        fpsCamera.GetComponentInChildren<AudioListener>().enabled = isControlled;
    51.        fpsCamera.GetComponentInChildren<CameraKick>().enabled = isControlled;
    52.        fpsCamera.GetComponentInChildren<LeanColliderDamage>().enabled = isControlled;
    53.        fpsCamera.GetComponentInChildren<LevelLoadFade>().enabled = isControlled;
    54.        fpsCamera.GetComponentInChildren<PainFade>().enabled = isControlled;
    55.      }
    56.      if (fpsPlayer != null) {
    57.        var fpsPlayerScript = fpsPlayer.GetComponent<FPSPlayer>();
    58.        fpsPlayerScript.enabled = isControlled;
    59.        fpsPlayer.GetComponent<HorizontalBob>().enabled = isControlled;
    60.        fpsPlayer.GetComponent<VerticalBob>().enabled = isControlled;
    61.        fpsPlayer.GetComponent<Ironsights>().enabled = isControlled;
    62.        fpsPlayer.GetComponent<FPSRigidBodyWalker>().enabled = isControlled;
    63.        fpsPlayer.GetComponent<Rigidbody>().useGravity = isControlled;
    64.        fpsPlayer.GetComponent<Rigidbody>().isKinematic = isProxy;
    65.        fpsPlayer.GetComponent<DragRigidbody>().enabled = isControlled;
    66.        fpsPlayer.GetComponent<WorldRecenter>().enabled = isControlled;
    67.        fpsPlayer.GetComponent<InputControl>().enabled = isControlled;
    68.        SetBehaviorEnabled<GUIText>(fpsPlayerScript.CrosshairGuiObj, isControlled);
    69.        SetBehaviorEnabled<GUIText>(fpsPlayerScript.healthGuiObj, isControlled);
    70.        SetBehaviorEnabled<GUIText>(fpsPlayerScript.thirstGuiObj, isControlled);
    71.        SetBehaviorEnabled<GUIText>(fpsPlayerScript.hungerGuiObj, isControlled);
    72.        SetBehaviorEnabled<GUIText>(fpsPlayerScript.helpGuiObj, isControlled);
    73.      }
    74.      if (fpsWeapons != null) {
    75.        var fpsWeaponsScript = fpsWeapons.GetComponent<PlayerWeapons>();
    76.        fpsWeaponsScript.SelectedWeapon += OnSelectedWeapon;
    77.        fpsWeaponsScript.enabled = isControlled;
    78.        fpsWeapons.GetComponent<GunSway>().enabled = isControlled;
    79.        fpsWeapons.GetComponent<WeaponEffects>().enabled = isControlled;
    80.        SetBehaviorEnabled<GUIText>(fpsWeaponsScript.ammoGuiObj, isControlled);
    81.        foreach (var weapon in fpsWeaponsScript.weaponOrder) {
    82.          var wasActive = weapon.activeInHierarchy;
    83.          weapon.SetActive(true);
    84.          var weaponBehavior = weapon.GetComponent<WeaponBehavior>();
    85.          weaponBehavior.enabled = isControlled;
    86.          if (isControlled) {
    87.            weaponBehavior.FiredWeapon += OnFiredWeapon;
    88.            weaponBehavior.DamagedTarget += OnDamagedTarget;
    89.          }
    90.          weapon.SetActive(wasActive);
    91.        }
    92.      }
    93.    }
    94.  
    95.    private void SetBehaviorEnabled<T>(GameObject go, bool value) where T : Behaviour {
    96.      if (go == null) return;
    97.      var behavior = go.GetComponent<T>();
    98.      if (behavior != null) behavior.enabled = value;
    99.    }
    100.  
    101.    private void OnSelectedWeapon(object sender, PlayerWeapons.SelectedWeaponEventArgs e) {
    102.      var equipEvent = EquipEvent.Create(Bolt.GlobalTargets.Everyone);
    103.      equipEvent.Player = GetComponent<BoltEntity>();
    104.      equipEvent.WeaponNumber = e.weaponNumber;
    105.      equipEvent.Send();
    106.    }
    107.  
    108.    private void OnFiredWeapon(object sender, WeaponBehavior.FiredWeaponEventArgs e) {
    109.      var fireEvent = FireEvent.Create(Bolt.GlobalTargets.Everyone);
    110.      fireEvent.Player = GetComponent<BoltEntity>();
    111.      fireEvent.WeaponNumber = e.weaponNumber;
    112.      fireEvent.Direction = e.direction;
    113.      fireEvent.Send();
    114.    }
    115.  
    116.    private void OnDamagedTarget(object sender, WeaponBehavior.DamagedTargetEventArgs e) {
    117.      var damageEvent = DamageEvent.Create(Bolt.GlobalTargets.Everyone);
    118.      var boltEntity = e.target.GetComponentInParent<BoltEntity>();
    119.      var boltAwareDamageable = e.target.GetComponentInParent<BoltAwareDamageable>() ?? e.target.GetComponentInChildren<BoltAwareDamageable>();
    120.      damageEvent.Player = boltEntity;
    121.      damageEvent.ID = (boltAwareDamageable == null) ? -1 : boltAwareDamageable.id;
    122.      damageEvent.Damage = e.damage;
    123.      damageEvent.AttackDir = e.attackDir;
    124.      damageEvent.AttackPos = e.attackPos;
    125.      damageEvent.Send();
    126.    }
    127.  
    128.    public void EquipWeaponOnProxy(BoltEntity entity, int weaponNumber) {
    129.      Debug.Log("Equip weapon " + weaponNumber + " on proxy body " + gameObject.GetInstanceID());
    130.    }
    131.  
    132.    public void FireWeaponOnProxy(BoltEntity entity, int weaponNumber, Vector3 direction) {
    133.      Debug.Log("Fire weapon " + weaponNumber + " on proxy body " + gameObject.GetInstanceID());
    134.    }
    135.  
    136. }
    BoltPlayerCallsbacks.cs:
    Code (csharp):
    1. using UnityEngine;
    2.  
    3. [BoltGlobalBehaviour(BoltNetworkModes.Server | BoltNetworkModes.Client)]
    4. public class BoltPlayerCallbacks : Bolt.GlobalEventListener {
    5.  
    6.    public override void SceneLoadLocalDone(string map) {
    7.      BoltEntity entity = SpawnPlayer();
    8.      entity.TakeControl();
    9.    }
    10.  
    11.    public override void ControlOfEntityGained(BoltEntity entity) {
    12.      entity.GetComponentInChildren<BoltPlayer>().isControlled = true;
    13.    }
    14.  
    15.  
    16.    public BoltEntity SpawnPlayer() {
    17.      BoltEntity player = BoltNetwork.Instantiate(BoltPrefabs.Player);
    18.  
    19.      // set position for entity
    20.      player.transform.localPosition = new Vector3(Random.Range(-8f, 8f), 4f, Random.Range(-8f, 8f));
    21.      player.transform.localEulerAngles = new Vector3(0f, Random.Range(0f, 360f), 0f);
    22.  
    23.      return player;
    24.    }
    25.  
    26. }
    GlobalCallsbacks.cs:
    Code (csharp):
    1. using UnityEngine;
    2.  
    3. [BoltGlobalBehaviour(BoltNetworkModes.Server | BoltNetworkModes.Client)]
    4. public class GlobalCallbacks : Bolt.GlobalEventListener {
    5.  
    6.    public override void OnEvent(DestroyEvent evnt) {
    7.      BoltAwareDestructible.BoltAwareDestroy(evnt.ID);
    8.    }
    9.  
    10.    public override void OnEvent(EquipEvent evnt) {
    11.      if (evnt.FromSelf) {
    12.        Debug.Log("I equipped weapon " + evnt.WeaponNumber);
    13.      } else {
    14.        Debug.Log(evnt.Player + " equipped weapon " + evnt.WeaponNumber);
    15.        evnt.Player.GetComponent<BoltPlayer>().EquipWeaponOnProxy(evnt.Player, evnt.WeaponNumber);
    16.      }
    17.    }
    18.  
    19.    public override void OnEvent(FireEvent evnt) {
    20.      if (evnt.FromSelf) {
    21.        Debug.Log("I fired weapon " + evnt.WeaponNumber);
    22.      } else {
    23.        Debug.Log(evnt.Player + " fired weapon " + evnt.WeaponNumber);
    24.        evnt.Player.GetComponent<BoltPlayer>().FireWeaponOnProxy(evnt.Player, evnt.WeaponNumber, evnt.Direction);
    25.      }
    26.    }
    27.  
    28.    public override void OnEvent(DamageEvent evnt) {
    29.      var targetEntityName = (evnt.Player == null) ? "non-player" : evnt.Player.ToString();
    30.      if (evnt.FromSelf) {
    31.        Debug.Log("I did " + evnt.Damage + " damage to " + targetEntityName + " / " + evnt.ID);
    32.      } else {
    33.        Debug.Log("Another player did " + evnt.Damage + " damage to " + targetEntityName + " / " + evnt.ID);
    34.      }
    35.      BoltAwareDamageable.BoltAwareApplyDamage(evnt.Player, evnt.ID, evnt.Damage, evnt.AttackDir, evnt.AttackPos);
    36.    }
    37.  
    38. }
    BoltAwareDamageable.cs:
    Code (csharp):
    1. using UnityEngine;
    2. using System.Collections;
    3. using System.Collections.Generic;
    4.  
    5. public class BoltAwareDamageable : MonoBehaviour {
    6.  
    7.    public static Dictionary<int, BoltAwareDamageable> damageables = new Dictionary<int, BoltAwareDamageable>();
    8.  
    9.    public int id;
    10.  
    11.    private void Awake() {
    12.      damageables.Add(id, this);
    13.    }
    14.  
    15.    private void OnDestroy() {
    16.      if (damageables.ContainsKey(id)) {
    17.        damageables.Remove(id);
    18.        var destroyEvent = DestroyEvent.Create(Bolt.GlobalTargets.Everyone);
    19.        destroyEvent.ID = id;
    20.        destroyEvent.Send();
    21.      }
    22.    }
    23.  
    24.    public static void BoltAwareApplyDamage(BoltEntity targetEntity, int id, int damage, Vector3 attackDir, Vector3 attackPos) {
    25.      if (targetEntity != null) {
    26.        ApplyDamageToTarget(targetEntity.gameObject, damage, attackDir, attackPos);
    27.      } else if (damageables.ContainsKey(id)) {
    28.        ApplyDamageToTarget(damageables[id].gameObject, damage, attackDir, attackPos);
    29.      }
    30.    }
    31.  
    32.    private static void ApplyDamageToTarget(GameObject target, int damage, Vector3 attackDir, Vector3 attackPos) {
    33.      switch (target.layer){
    34.      case 11://Player
    35.        if (target.GetComponentInChildren<FPSPlayer>()) {
    36.          target.GetComponentInChildren<FPSPlayer>().ApplyDamage(damage);
    37.        }
    38.        break;
    39.      case 13://hit object is an NPC
    40.        if(target.GetComponent<CharacterDamage>()){
    41.          target.GetComponent<CharacterDamage>().ApplyDamage(damage, attackDir, attackPos);
    42.        }
    43.        break;
    44.      case 9://hit object is an apple
    45.        if(target.GetComponent<AppleFall>()){
    46.          target.GetComponent<AppleFall>().ApplyDamage(damage);
    47.        }
    48.        break;
    49.      case 19://hit object is a breakable or explosive object
    50.        if(target.GetComponent<BreakableObject>()){
    51.          target.GetComponent<BreakableObject>().ApplyDamage(damage);
    52.        }else if(target.GetComponent<ExplosiveObject>()){
    53.          target.GetComponent<ExplosiveObject>().ApplyDamage(damage);
    54.        }else if(target.GetComponent<MineExplosion>()){
    55.          target.GetComponent<MineExplosion>().ApplyDamage(damage);
    56.        }
    57.        break;
    58.      default:
    59.        break;
    60.      }
    61.    }
    62.  
    63. }
    BoltAwareDestructible.cs:
    Code (csharp):
    1. using UnityEngine;
    2. using System.Collections;
    3. using System.Collections.Generic;
    4.  
    5. public class BoltAwareDestructible : MonoBehaviour {
    6.  
    7.    public static Dictionary<int, BoltAwareDestructible> destructibles = new Dictionary<int, BoltAwareDestructible>();
    8.  
    9.    public int id;
    10.  
    11.    private void Awake() {
    12.      destructibles.Add(id, this);
    13.    }
    14.  
    15.    private void OnDestroy() {
    16.      if (destructibles.ContainsKey(id)) {
    17.        destructibles.Remove(id);
    18.        var destroyEvent = DestroyEvent.Create(Bolt.GlobalTargets.Everyone);
    19.        destroyEvent.ID = id;
    20.        destroyEvent.Send();
    21.      }
    22.    }
    23.  
    24.    public static void BoltAwareDestroy(int id) {
    25.      if (destructibles.ContainsKey(id)) {
    26.        Destroy(destructibles[id].gameObject);
    27.      }
    28.    }
    29.  
    30. }
    No guarantee that this is the absolute best way to implement multiplayer. Maybe Bolt commands would have been better than Bolt events. I had to learn Bolt as I went through this. Bolt has a really nice design, but it's a bit different from PUN and Unity's built-in networking.
     
    Last edited: Feb 1, 2015
    RealAspireGames and Eyehawk like this.
  17. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,657
    If you're implementing multiplayer, you might want to bookmark this thread where they're discussing anti-cheat measures for non-authoritative servers.
     
  18. RealAspireGames

    RealAspireGames

    Joined:
    Dec 24, 2013
    Posts:
    265
    Just one quick question how do I spawn my player I followed the steps that you have provided now just wondering how to set up spawning? Do I need to attach the player global callbacks to an empty gameobject?
     
  19. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,657
    Hi @godofwarfare115 - No, those scripts shouldn't be attached to any GameObjects. When you click the green down arrow (which is the same as Assets > Bolt Engine > Compile Assembly), Bolt will find the script and set up spawning automatically. The only scripts that should be on the Player GameObject are BoltEntity and BoltPlayer.
     
  20. eridani

    eridani

    Joined:
    Aug 30, 2012
    Posts:
    655
    @TonyLi do you think Unity 5 networking will supersede Bolt or do you foresee Bolt being better or having more functionality?
     
  21. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,657
    Just my thoughts - I haven't used Unity 5 networking. It looks like it'll be good, but it might be a while before bugs are worked out. If you're working on a multiplayer RFPS project now or in the very near future, you might want to go with Bolt. Again, no guarantees that the way I posted is the best way to do it. Also, Bolt doesn't have a lobby or matchmaking service. You'll have to implement this on your own. Unity 5's networking will have some kind of matchmaking service. Another bit of work is adding a proxy body that other players can see. But you'll have to do this regardless of whether you use Bolt or Unity 5 networking. (BTW, Bolt is today's 24 Hour Deal, so if you're thinking of buying it, now's the time.)
     
    eridani likes this.
  22. mentolatux

    mentolatux

    Joined:
    Nov 2, 2014
    Posts:
    240
    hi all , i need help to change character zombie, i assigned all script from old zombie to new zombie prefab , i have animation working on new zombie and i assigned to prefab, i apply prefab with all files assigned an wen i play the svene the new zombie prefab remain in idle modee, i need a tutorial and if you have share here plzz.
     
  23. BlurTimeTeam

    BlurTimeTeam

    Joined:
    Jan 29, 2014
    Posts:
    20
    What can i do whan I want working Realistic FPS Prefab + Advanced Sniper Starter Kit? Like this:
     
  24. mentolatux

    mentolatux

    Joined:
    Nov 2, 2014
    Posts:
    240
    nice , i like it
     
  25. mentolatux

    mentolatux

    Joined:
    Nov 2, 2014
    Posts:
    240
    Blur time add me on skipe - mentolatux
     
  26. TheNorthridge

    TheNorthridge

    Joined:
    Jan 4, 2012
    Posts:
    193
  27. eridani

    eridani

    Joined:
    Aug 30, 2012
    Posts:
    655
    What is this? A Unity open world system?
     
  28. bow1D

    bow1D

    Joined:
    Jan 24, 2015
    Posts:
    2
    Hi all, I've a question on Bolt/RFPSP. I folllowed TonyLi tutorial Thank for this, :) but when i launch with Bolt Entity/Player activated on player for network , i loose mouse fonctionnality, anyone have a simillar issue? or a idea to resolve this.
     
  29. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,657
    Does the mouse work if you click Play As Server in the Bolt Scenes window? If so, does it work if you launch multiple instances on the same machine using the Debug Start button? How about if you launch multiple instances of a build on the same machine?

    By "losing mouse functionality," what do you mean? Can you mouse-look?
     
  30. bow1D

    bow1D

    Joined:
    Jan 24, 2015
    Posts:
    2
    thank a lot. the mouse look work with play as server ;)
     
  31. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,657
    But not Debug Start? If you click Debug Start, it should play one instance (the server) in the Unity editor, and open one or more instances (clients) in separate windows. Does the mouse-look work for the player in the Unity editor instance?

    Also, double- and triple-check all of the steps in my post. The setup is very particular. If you miss even one little thing, it might not work correctly.
     
  32. mentolatux

    mentolatux

    Joined:
    Nov 2, 2014
    Posts:
    240
    anybody know to chanage zombie ? an tutorial something will be great
     
  33. Defcon44

    Defcon44

    Joined:
    Aug 19, 2013
    Posts:
    400
    We have it to speak in about numerous resumed in the previous pages, thank you for making a minimum of search before posting the same questions
     
    Deleted User and thenamesace like this.
  34. bigd

    bigd

    Joined:
    Feb 14, 2014
    Posts:
    40
    @ TonyLi

    Your contribution with the RFPS and BOLT is great; however, I'm left with a problem. My understanding is the main benefit of Bolt is it makes it easy to have authoritative movement / shooting which all depend on the player being a non-rigid body due to the limitations of simulating physics over the network.

    Excuse my inexperience with this subject, but would a rigidbody solution like you've provided be applicable in a cheater-less multiplayer game? It seems like you would need to have a Character Controlled version for it to work right in an authoritative environment.

    I suppose it brings up another question on whether or not some of the thirdparty Anti-Cheat programs out there like Easy Anti-Cheat, would help in this situation.
     
  35. zugsoft

    zugsoft

    Joined:
    Apr 23, 2014
    Posts:
    453
    Hello,

    I just finish my multiplayer scripts to play with 8 players on my dedicated server.
    No need Bolt, or Photon, or other.
    I just use System.Net.Sockets with UDP and TCP protocol in a separate Thread.
    I include a simple Chat system.

    For moment I can play up to 8 players on MacOS, PC, Android, iPad, iPhone and Windows Phone Mobile in the same room.
    For iOS and Android I must use Good ol' Sockets because System.Net.Sockets is only available for Unity PRO.

    I made some benchmark, and simulated 800 players (8 players x 100rooms) and no problem for my dedicated server.

    I hope to make you a APK for Android Users for the next week.

    Good night.
     
    Defcon44 likes this.
  36. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,657
    You're right that it's easier to cheat with non-authoritative servers, but ultimately if you can connect to a server you can cheat, authoritative or not. RFPS would have to be rewritten to use a CharacterController, or to use a physics engine that allows "rewind" to sync with the server, or use an authoritative server and accept some lag either in input responsiveness or in movement. In lieu of that, you need to implement different anti-cheat measures with non-authoritative servers. I'm not a networking expert, but you could do things like detect if a client says it's moving faster than it's supposed to be able to move.
     
    sluice and Defcon44 like this.
  37. bigd

    bigd

    Joined:
    Feb 14, 2014
    Posts:
    40
    Thanks TonyLi, that clarified some things for me! I think for my case I'm going to have to look and see what makes the most sense. Ideally, I'm looking to have ~100 people on the server at one time, although not necessarily within close proximity. This may be too much for a fully authoritative server to handle and I'd have to go a more semi-authoritative way and work in a few of those anti-cheat methods you mentioned.
     
  38. zugsoft

    zugsoft

    Joined:
    Apr 23, 2014
    Posts:
    453
  39. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,657
    Can you share how you did it? Can the players shoot each other and/or other things in the level?
     
  40. zugsoft

    zugsoft

    Joined:
    Apr 23, 2014
    Posts:
    453
    Each player can shot other players.
    I only remove all enemy RPFS scripts for each enemy, and add my enemyScript.cs
    Add my playerScript.cs to the Player
    And I made a Socket server on my dedicated server hosted on OVH in C, but maybe I will make a Mono C# server.
    I include a Chat system, and a php server to save each score.

    Maybe I will sell my scripts $10 for RFPS and rent a 20CCU for $5 by month, 50CCU for $10, 100CCU for $15 by month on my dedicated server.

    If you have a Android Mobile, I can send you a apk.
     
    Last edited: Jan 28, 2015
  41. eridani

    eridani

    Joined:
    Aug 30, 2012
    Posts:
    655
    Can I ask what mobile controller you used? Or did you make your own. Thanks!
     
  42. zugsoft

    zugsoft

    Joined:
    Apr 23, 2014
    Posts:
    453
    I made my own controller.
     

    Attached Files:

    Legorobotdude, QuadMan and eridani like this.
  43. RealAspireGames

    RealAspireGames

    Joined:
    Dec 24, 2013
    Posts:
    265
    Just a quick question how would you go about respawning, Everything is working fantastic just a few bugs but nothing to be worried about. But it seems when the player kills another player the game crashes. I assume this is a network respawn issues. Just wondering if there is a way to fix this?
     
  44. zugsoft

    zugsoft

    Joined:
    Apr 23, 2014
    Posts:
    453
    For your problem,

    I modified Die() method in FPSPlayer.cs and Die () method in CharacterDamage.cs
    In CharacterDamage.cs you must delete Destroy(transform.parent.gameObject); and Destroy(transform.gameObject); and replace them by something else.

    I am working on a Java server, everybody with a dedicated server on Windows, Linux, MacOS could use it.
    My old server was wrote in C , and it's very difficult to understand and to modify, I created this server 2 years ago for my first FPS game on WindowsPhone7, but my first Java benchmark are very good, It's comparable to my C benchmark.
     
  45. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,657
    Like @menfou says, edit the Die() message. You could look for a BoltPlayer component. If the GameObject has one, respawn instead of destroying the GameObject:
    Code (csharp):
    1. if (GetComponent<BoltPlayer>() != null) {
    2.     // put your respawn code here
    3. } else {
    4.     // keep the original die code here
    5. }
    I didn't implement any kind of respawn in my original post because I figured it's very game-dependent. The code just spawns players at a random position. You could tag a bunch of empty GameObjects as, say, a new tag "Spawnpoint". When you spawn or respawn, run GameObject.FindGameObjectsWithTag("Spawnpoint") and randomly choose one of the results. Then put the player in that position and reset its stats (health, weapon, etc.).
     
  46. BlurTimeTeam

    BlurTimeTeam

    Joined:
    Jan 29, 2014
    Posts:
    20
    When up new update?
     
  47. Dotta4

    Dotta4

    Joined:
    Sep 26, 2013
    Posts:
    8
    Hi,

    Love the look of the pack but just curious when or if you plan to add a navigation update for the enemy ai? I know currently there's a way point system but from what I can tell once the ai is chasing the player, there's no obstacle avoidance. Is there going to be an update for this any time soon?

    Thanks in advance for any help :)
     
  48. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,657
    The developer, Azuline Studios, has indicated that the next update may not be available for quite some time. Fortunately RFPS is designed modularly enough that you can easily supplement it with third-party addons. You can use Unity's built-in navigation system for obstacle avoidance or Behavior Designer's RFPS third-party support for advanced AI with behavior trees and movement. And of course the Dialogue System for conversations, barks, quests, and saving/loading games. ;) It also works well with other assets such as HUD Waypoint and NJG MiniMap.
     
    chelnok likes this.
  49. Dotta4

    Dotta4

    Joined:
    Sep 26, 2013
    Posts:
    8
    That's all I needed to know! *Grabs credit card* ;)
     
  50. zugsoft

    zugsoft

    Joined:
    Apr 23, 2014
    Posts:
    453
    I use Unity navmesh system for my Game , vert easy to use in RFPS, Just 5 lines in AI.cs