public void Initialize() { this.MyAnimator = GetComponentInChildren<Animator>(); this.MyReference = GetComponentInChildren<CharacterReference>(); this.MyEventHandler = GetComponentInChildren<CharacterEventHandler>(); this.MyReference.ParentCharacter = this; //setup animator parameters initial values this.MyAnimator.SetBool("IsAiming", false); this.MyAnimator.SetBool("IsSneaking", false); this.Destination = transform.position; MyNavAgent = GetComponent<NavMeshAgent>(); UpperBodyState = HumanUpperBodyStates.Idle; ActionState = HumanActionStates.None; //load aim target and look target GameObject aimTarget = (GameObject)GameObject.Instantiate(Resources.Load("IKAimTargetRoot")); GameObject lookTarget = (GameObject)GameObject.Instantiate(Resources.Load("IKLookTarget")); AimTargetRoot = aimTarget.transform; AimTarget = AimTargetRoot.Find("IKAimTarget").transform; LookTarget = lookTarget.transform; this.MyAimIK = GetComponentInChildren<AimIK>(); this.MyAimIK.solver.target = AimTarget; this.MyAimIK.solver.IKPositionWeight = 0; this.MyAimIK.solver.SmoothDisable(); this.MyLeftHandIK = GetComponentInChildren<LeftHandIKControl>(); this.MyLeftHandIK.Initialize(); this.MyHeadIK = GetComponentInChildren<LookAtIK>(); this.MyHeadIK.solver.target = LookTarget; this.MyStatus = new CharacterStatus(); this.MyStatus.Initialize(); //each time a human char is initialized it's added to NPC manager's list of human characters to keep track of GameManager.Inst.NPCManager.AddHumanCharacter(this); CurrentAnimState = new HumanAnimStateIdle(this); //SendCommand(HumanCharCommands.Unarm); MyAI = GetComponent<AI>(); MyAI.Initialize(this); //subscribe events this.MyEventHandler.OnLongGunPullOutFinish += OnLongGunPullOutFinish; this.MyEventHandler.OnLongGunPutAwayFinish += OnLongGunPutAwayFinish; this.MyEventHandler.OnPistolPullOutFinish += OnPistolPullOutFinish; this.MyEventHandler.OnPistolPutAwayFinish += OnPistolPutAwayFinish; this.MyEventHandler.OnReloadFinish += OnReloadFinish; this.MyEventHandler.OnThrowFinish += OnThrowFinish; this.MyEventHandler.OnThrowLeaveHand += OnThrowLeaveHand; this.MyEventHandler.OnBulletInjury += OnBulletInjury; this.MyEventHandler.OnDeath += OnDeath; }
public void Initialize() { //load aim target and look target GameObject aimTarget = (GameObject)GameObject.Instantiate(Resources.Load("IKAimTargetRoot")); GameObject lookTarget = (GameObject)GameObject.Instantiate(Resources.Load("IKLookTarget")); AimTargetRoot = aimTarget.transform; AimTarget = AimTargetRoot.Find("IKAimTarget").transform; LookTarget = lookTarget.transform; LoadCharacterModel(this.CharacterID); this.MyEventHandler = GetComponent<CharacterEventHandler>(); this.Destination = transform.position; MyNavAgent = GetComponent<NavMeshAgent>(); UpperBodyState = HumanUpperBodyStates.Idle; ActionState = HumanActionStates.None; Markers = new CharacterMarkerSet(); this.MyStatus = new CharacterStatus(); this.MyStatus.Initialize(); this.Stealth = new CharacterStealth(this); this.Inventory = new CharacterInventory(); //each time a human char is initialized it's added to NPC manager's list of human characters to keep track of GameManager.Inst.NPCManager.AddHumanCharacter(this); CurrentAnimState = new HumanAnimStateIdle(this); //SendCommand(CharacterCommands.Unarm); MyAI = GetComponent<AI>(); MyAI.Initialize(this); this.ArmorSystem = new ArmorSystem(this); _meleeStrikeStage = 0; _isLowThrow = false; }
public override void SendCommand(HumanCharCommands command) { //following commands are not given by AI or user. All commands that will unlock the body go here if(IsBodyLocked) { return; } //following commands are given by AI or user, and can be locked CurrentAnimState.SendCommand(command); if(command == HumanCharCommands.Crouch) { CapsuleCollider collider = GetComponent<CapsuleCollider>(); collider.height = 1.3f; collider.center = new Vector3(0, 0.6f, 0); } if(command == HumanCharCommands.StopCrouch) { CapsuleCollider collider = GetComponent<CapsuleCollider>(); collider.height = 1.7f; collider.center = new Vector3(0, 1, 0); } if(command == HumanCharCommands.Aim && GetCurrentAnimWeapon() != WeaponAnimType.Unarmed && CurrentStance != HumanStances.Sprint) { if(ActionState == HumanActionStates.None) { UpperBodyState = HumanUpperBodyStates.Aim; MyAimIK.solver.SmoothEnable(2.5f); MyLeftHandIK.SmoothEnable(); MyHeadIK.solver.SmoothDisable(); MyAnimator.SetBool("IsAiming", true); //StartCoroutine(WaitAndEnableAimIK(0.2f)); } else if(ActionState == HumanActionStates.SwitchWeapon) { UpperBodyState = HumanUpperBodyStates.Aim; } } if(command == HumanCharCommands.StopAim && ActionState == HumanActionStates.None) { UpperBodyState = HumanUpperBodyStates.Idle; MyAimIK.solver.SmoothDisable(9); MyHeadIK.solver.SmoothEnable(); MyAnimator.SetBool("IsAiming", false); if(GetCurrentAnimWeapon() == WeaponAnimType.Pistol) { MyLeftHandIK.SmoothDisable(9); } //Debug.Log("stopping aim"); } if(command == HumanCharCommands.Sprint) { if(CurrentStance == HumanStances.Crouch || CurrentStance == HumanStances.CrouchRun) { CurrentStance = HumanStances.CrouchRun; } else { CurrentStance = HumanStances.Sprint; MyAimIK.solver.SmoothDisable(); MyHeadIK.solver.SmoothDisable(); } } if(command == HumanCharCommands.StopSprint) { if(UpperBodyState == HumanUpperBodyStates.Aim) { MyAimIK.solver.SmoothEnable(); } if(CurrentStance == HumanStances.CrouchRun || CurrentStance == HumanStances.Crouch) { CurrentStance = HumanStances.Crouch; } else { CurrentStance = HumanStances.Run; } MyHeadIK.solver.SmoothEnable(); } if(command == HumanCharCommands.SwitchWeapon2) { Debug.Log("current human action state " + ActionState); if(ActionState == HumanActionStates.None) { MyLeftHandIK.SmoothDisable(15); MyAimIK.solver.SmoothDisable(9); MyAnimator.SetInteger("WeaponType", 2); SwitchWeapon("AK47"); ActionState = HumanActionStates.SwitchWeapon; } } if(command == HumanCharCommands.SwitchWeapon1) { if(ActionState == HumanActionStates.None) { if(UpperBodyState == HumanUpperBodyStates.Aim) { //MyLeftHandIK.SmoothEnable(); } else { } MyLeftHandIK.SmoothDisable(15); MyAimIK.solver.SmoothDisable(9); MyAnimator.SetInteger("WeaponType", 1); SwitchWeapon("44MagnumRevolver"); ActionState = HumanActionStates.SwitchWeapon; } } if(command == HumanCharCommands.Unarm) { if(ActionState == HumanActionStates.None) { MyLeftHandIK.SmoothDisable(); UpperBodyState = HumanUpperBodyStates.Idle; MyAimIK.solver.SmoothDisable(); MyHeadIK.solver.SmoothEnable(); MyAnimator.SetBool("IsAiming", false); MyAnimator.SetInteger("WeaponType", 0); SwitchWeapon(""); ActionState = HumanActionStates.SwitchWeapon; } } if(command == HumanCharCommands.PullTrigger) { if(ActionState != HumanActionStates.None || UpperBodyState != HumanUpperBodyStates.Aim) { return; } if(GetCurrentAnimWeapon() == WeaponAnimType.Longgun || GetCurrentAnimWeapon() == WeaponAnimType.Pistol) { // this.MyReference.CurrentWeapon.GetComponent<Gun>().TriggerPull(); } } if(command == HumanCharCommands.ReleaseTrigger) { if(ActionState != HumanActionStates.None || UpperBodyState != HumanUpperBodyStates.Aim) { return; } if(GetCurrentAnimWeapon() == WeaponAnimType.Longgun || GetCurrentAnimWeapon() == WeaponAnimType.Pistol) { // this.MyReference.CurrentWeapon.GetComponent<Gun>().TriggerRelease(); } } if(command == HumanCharCommands.Reload) { if(ActionState == HumanActionStates.None && this.MyReference.CurrentWeapon != null) { if(GetCurrentAnimWeapon() == WeaponAnimType.Longgun || GetCurrentAnimWeapon() == WeaponAnimType.Pistol) { MyAimIK.solver.SmoothDisable(); MyAnimator.SetTrigger("Reload"); MyLeftHandIK.SmoothDisable(); } MyHeadIK.solver.SmoothDisable(); ActionState = HumanActionStates.Reload; } } if(command == HumanCharCommands.CancelReload) { if(ActionState == HumanActionStates.Reload && this.MyReference.CurrentWeapon != null) { Debug.Log("cancel reload"); if(UpperBodyState == HumanUpperBodyStates.Aim) { MyAimIK.solver.SmoothEnable(); MyAnimator.SetTrigger("CancelReload"); } else { MyAnimator.SetTrigger("CancelReload"); } if(MyAnimator.GetInteger("WeaponType") == (int)WeaponAnimType.Longgun) { MyLeftHandIK.SmoothEnable(); } else { Debug.Log("done reloading pistol " + UpperBodyState); if(UpperBodyState == HumanUpperBodyStates.Aim) { MyLeftHandIK.SmoothEnable(); } else { MyLeftHandIK.SmoothDisable(); } } MyHeadIK.solver.SmoothEnable(); ActionState = HumanActionStates.None; } } if(command == HumanCharCommands.ThrowGrenade) { if(ActionState != HumanActionStates.None) { return; } if(UpperBodyState == HumanUpperBodyStates.Aim) { //MyAimIK.solver.SmoothDisable(); } if(this.MyReference.CurrentWeapon != null && MyAnimator.GetInteger("WeaponType") == (int)WeaponAnimType.Longgun) { MyLeftHandIK.SmoothEnable(); } //MyHeadIK.solver.SmoothDisable(1); //move weapon to torso mount so that right hand is free if(this.MyReference.CurrentWeapon != null) { this.MyReference.CurrentWeapon.transform.parent = this.MyReference.TorsoWeaponMount.transform; } MyAnimator.SetTrigger("ThrowGrenade"); _throwTarget = this.AimPoint; _throwDir = this.AimPoint - transform.position; IsBodyLocked = true; ActionState = HumanActionStates.Throw; _thrownObjectInHand = ((GameObject)GameObject.Instantiate(Resources.Load("TestGrenade"))).GetComponent<ThrownObject>(); _thrownObjectInHand.GetComponent<Rigidbody>().isKinematic = true; _thrownObjectInHand.transform.parent = this.MyReference.RightHandWeaponMount.transform; _thrownObjectInHand.transform.localPosition = _thrownObjectInHand.InHandPosition; _thrownObjectInHand.transform.localEulerAngles = _thrownObjectInHand.InHandRotation; } }
public override void SendCommand(CharacterCommands command) { if(!IsBodyLocked && !IsMoveLocked) { CurrentAnimState.SendCommand(command); } //following commands are not given by AI or user. All commands that will unlock the body go here if(command == CharacterCommands.StopAim) { if(ActionState == HumanActionStates.None) { MyAI.WeaponSystem.StopFiringRangedWeapon(); UpperBodyState = HumanUpperBodyStates.Idle; MyAimIK.solver.SmoothDisable(6); MyHeadIK.SmoothEnable(); MyAnimator.SetBool("IsAiming", false); MyReference.Flashlight.transform.localEulerAngles = new Vector3(27, 0, 0); if(GetCurrentAnimWeapon() == WeaponAnimType.Pistol || GetCurrentAnimWeapon() == WeaponAnimType.Grenade) { MyLeftHandIK.InstantDisable(); } } else { UpperBodyState = HumanUpperBodyStates.Idle; } _isHipAiming = false; //Debug.LogError("stopping aim " + ActionState + " " + this.name); } if(command == CharacterCommands.Cancel) { if(ActionState == HumanActionStates.Strangle) { ActionState = HumanActionStates.None; MyAnimator.SetTrigger("Cancel"); Vector3 lineOfSight = _strangleTarget.transform.position - transform.position; transform.position = _strangleTarget.transform.position - lineOfSight.normalized; if(_strangleTarget.IsAlive) { _strangleTarget.IsBodyLocked = false; _strangleTarget.MyAnimator.SetTrigger("Cancel"); _strangleTarget = null; } IsBodyLocked = false; MyNavAgent.enabled = true; } } if(command == CharacterCommands.RightAttack) { ActionState = HumanActionStates.Melee; _meleeStrikeStage = 0; MyAnimator.SetTrigger("RightAttack"); IsMoveLocked = true; MyHeadIK.SmoothDisable(9); Debug.Log("starting right attack"); } if(command == CharacterCommands.LeftAttack) { ActionState = HumanActionStates.Melee; _meleeStrikeStage = 0; Vector3 lookDir = LookTarget.position - transform.position; lookDir = new Vector3(lookDir.x, 0, lookDir.z); Vector3 destDir = MyNavAgent.velocity.normalized; destDir = new Vector3(destDir.x, 0, destDir.z); float lookDestAngle = Vector3.Angle(lookDir, destDir); if(MyNavAgent.velocity.magnitude > 0f && lookDestAngle < 70) { MyAnimator.SetTrigger("ComboAttack"); } else { MyAnimator.SetTrigger("LeftAttack"); IsMoveLocked = true; } MyHeadIK.SmoothDisable(9); Debug.Log("starting left attack"); } if(command == CharacterCommands.Block) { ActionState = HumanActionStates.Block; this.MyLeftHandIK.Target = MyReference.CurrentWeapon.GetComponent<Weapon>().ForeGrip; this.MyLeftHandIK.SmoothEnable(20); _meleeStrikeStage = 0; MyAnimator.SetTrigger("Block"); IsMoveLocked = true; } if(IsBodyLocked) { return; } //following commands are given by AI or user, and can be locked if(command == CharacterCommands.Crouch) { CapsuleCollider collider = GetComponent<CapsuleCollider>(); collider.height = 1f; collider.center = new Vector3(0, 0.5f, 0); } if(command == CharacterCommands.StopCrouch) { CapsuleCollider collider = GetComponent<CapsuleCollider>(); collider.height = 1.7f; collider.center = new Vector3(0, 1, 0); } if((command == CharacterCommands.Aim || command == CharacterCommands.HipAim) && CurrentStance != HumanStances.Sprint) { if(MyAI.ControlType != AIControlType.Player) Debug.Log("action state " + ActionState + " weapon type " + GetCurrentAnimWeapon() + " upper body state " + UpperBodyState); if((ActionState == HumanActionStates.None || ActionState == HumanActionStates.Twitch) && GetCurrentAnimWeapon() != WeaponAnimType.Unarmed && !MyAnimator.GetBool("IsAiming")) { if(MyAI.ControlType != AIControlType.Player) Debug.Log(command); if(GetCurrentAnimWeapon() == WeaponAnimType.Grenade || GetCurrentAnimWeapon() == WeaponAnimType.Tool) { MyLeftHandIK.SmoothDisable(6); UpperBodyState = HumanUpperBodyStates.HalfAim; } else { UpperBodyState = HumanUpperBodyStates.Aim; if(GetCurrentAnimWeapon() == WeaponAnimType.Pistol) { MyLeftHandIK.InstantDisable(); } MyLeftHandIK.SmoothEnable(6); MyAimIK.solver.InstantDisable(); MyAimIK.solver.CurvedEnable(6f); //if(GetCurrentAnimWeapon() != WeaponAnimType.Melee) { MyHeadIK.InstantDisable(); } MyAnimator.SetBool("IsAiming", true); if(MyAI.ControlType != AIControlType.Player) Debug.LogError("Animation parameter IsAiming has been set"); MyReference.Flashlight.transform.localEulerAngles = new Vector3(0, 0, 0); } /* //draw a new grenade if there isn't one if(GetCurrentAnimWeapon() == WeaponAnimType.Grenade) { if(_thrownObjectInHand == null) { DrawNextGrenade(); } } */ } else if(ActionState == HumanActionStates.SwitchWeapon) { if(UpperBodyState == HumanUpperBodyStates.Aim && !MyAnimator.GetBool("IsAiming")) { MyLeftHandIK.InstantDisable(); MyLeftHandIK.SmoothEnable(6); MyAimIK.solver.InstantDisable(); MyAimIK.solver.SmoothEnable(6f); MyHeadIK.InstantDisable(); MyAnimator.SetBool("IsAiming", true); if(MyAI.ControlType != AIControlType.Player) Debug.LogError("Animation parameter IsAiming has been set"); MyReference.Flashlight.transform.localEulerAngles = new Vector3(0, 0, 0); } else { UpperBodyState = HumanUpperBodyStates.Aim; } } else if(GetCurrentAnimWeapon() == WeaponAnimType.Unarmed) { SendCommand(MyAI.WeaponSystem.GetBestWeaponChoice()); } if(command == CharacterCommands.HipAim) { _isHipAiming = true; } else if(command == CharacterCommands.Aim) { _isHipAiming = false; } } if(command == CharacterCommands.Sprint) { /* if(CurrentStance == HumanStances.Crouch || CurrentStance == HumanStances.CrouchRun) { CurrentStance = HumanStances.CrouchRun; } else*/ { CurrentStance = HumanStances.Sprint; MyAimIK.solver.SmoothDisable(); MyHeadIK.InstantDisable(); } } if(command == CharacterCommands.StopSprint) { if(UpperBodyState == HumanUpperBodyStates.Aim) { MyAimIK.solver.SmoothEnable(); } if(CurrentStance == HumanStances.CrouchRun || CurrentStance == HumanStances.Crouch) { CurrentStance = HumanStances.Crouch; } else { CurrentStance = HumanStances.Run; } MyHeadIK.SmoothEnable(); } if(command == CharacterCommands.SwitchWeapon2) { if((ActionState == HumanActionStates.None || ActionState == HumanActionStates.Twitch) && MyAI.WeaponSystem.PrimaryWeapon != null) { CsDebug.Inst.CharLog(this, "Start switching weapon2"); MyLeftHandIK.SmoothDisable(15); MyAimIK.solver.SmoothDisable(9); //SwitchWeapon(Inventory.RifleSlot); _weaponToSwitch = Inventory.RifleSlot; if(MyAI.WeaponSystem.PrimaryWeapon.IsRanged) { MyAnimator.SetInteger("WeaponType", 2); } else { MyAnimator.SetInteger("WeaponType", 3); } ActionState = HumanActionStates.SwitchWeapon; } } if(command == CharacterCommands.SwitchWeapon1) { if((ActionState == HumanActionStates.None || ActionState == HumanActionStates.Twitch) && MyAI.WeaponSystem.SideArm != null) { if(UpperBodyState == HumanUpperBodyStates.Aim) { //MyLeftHandIK.SmoothEnable(); } else { } MyLeftHandIK.SmoothDisable(15); MyAimIK.solver.SmoothDisable(9); MyAnimator.SetInteger("WeaponType", 1); //SwitchWeapon(Inventory.SideArmSlot); _weaponToSwitch = Inventory.SideArmSlot; ActionState = HumanActionStates.SwitchWeapon; } } if(command == CharacterCommands.SwitchThrown) { if(ActionState == HumanActionStates.None) { MyLeftHandIK.SmoothDisable(6); MyAimIK.solver.SmoothDisable(9); MyAnimator.SetInteger("WeaponType", -1); //SwitchWeapon(Inventory.ThrowSlot); _weaponToSwitch = Inventory.ThrowSlot; ActionState = HumanActionStates.SwitchWeapon; } } if(command == CharacterCommands.SwitchTool) { if(ActionState == HumanActionStates.None) { GameObject.Destroy(this.MyReference.CurrentWeapon); if(_thrownObjectInHand != null) { GameObject.Destroy(_thrownObjectInHand.gameObject); } MyLeftHandIK.SmoothDisable(6); MyAimIK.solver.SmoothDisable(9); MyAnimator.SetInteger("WeaponType", -2); //SwitchWeapon("ThrowingRock"); ActionState = HumanActionStates.SwitchWeapon; } } if(command == CharacterCommands.Unarm) { if(ActionState == HumanActionStates.None) { MyLeftHandIK.SmoothDisable(); UpperBodyState = HumanUpperBodyStates.Idle; MyAimIK.solver.SmoothDisable(); MyHeadIK.SmoothEnable(); MyAnimator.SetBool("IsAiming", false); MyAnimator.SetInteger("WeaponType", 0); //SwitchWeapon(null); _weaponToSwitch = null; ActionState = HumanActionStates.SwitchWeapon; } } if(command == CharacterCommands.PullTrigger) { if(ActionState != HumanActionStates.None || UpperBodyState != HumanUpperBodyStates.Aim) { return; } if(GetCurrentAnimWeapon() == WeaponAnimType.Longgun || GetCurrentAnimWeapon() == WeaponAnimType.Pistol) { // this.MyReference.CurrentWeapon.GetComponent<Gun>().TriggerPull(); } } if(command == CharacterCommands.ReleaseTrigger) { if(ActionState != HumanActionStates.None || UpperBodyState != HumanUpperBodyStates.Aim) { return; } if(GetCurrentAnimWeapon() == WeaponAnimType.Longgun || GetCurrentAnimWeapon() == WeaponAnimType.Pistol) { // this.MyReference.CurrentWeapon.GetComponent<Gun>().TriggerRelease(); } } if(command == CharacterCommands.Reload) { if(ActionState == HumanActionStates.None && this.MyReference.CurrentWeapon != null) { GunMagazine magazine = this.MyReference.CurrentWeapon.GetComponent<GunMagazine>(); if(magazine != null && magazine.AmmoLeft < magazine.MaxCapacity) { GridItemData ammo = this.Inventory.FindItemInBackpack(magazine.LoadedAmmoID); if(ammo != null) { if(GetCurrentAnimWeapon() == WeaponAnimType.Longgun || GetCurrentAnimWeapon() == WeaponAnimType.Pistol) { MyAimIK.solver.SmoothDisable(12); MyAnimator.SetInteger("ReloadType", (int)magazine.ReloadType); MyAnimator.SetTrigger("Reload"); MyLeftHandIK.SmoothDisable(); } MyHeadIK.SmoothDisable(); ActionState = HumanActionStates.Reload; } } } } if(command == CharacterCommands.CancelReload) { if(ActionState == HumanActionStates.Reload && this.MyReference.CurrentWeapon != null) { Debug.Log("cancel reload"); ActionState = HumanActionStates.None; if(UpperBodyState == HumanUpperBodyStates.Aim) { MyAimIK.solver.SmoothEnable(); MyAnimator.SetTrigger("CancelReload"); } else { MyAnimator.SetTrigger("CancelReload"); } if(MyAnimator.GetInteger("WeaponType") == (int)WeaponAnimType.Longgun) { MyLeftHandIK.SmoothEnable(); } else { Debug.Log("done reloading pistol " + UpperBodyState); if(UpperBodyState == HumanUpperBodyStates.Aim) { MyLeftHandIK.SmoothEnable(); } else { //MyLeftHandIK.SmoothDisable(); SendCommand(CharacterCommands.StopAim); } } MyHeadIK.SmoothEnable(); } } if(command == CharacterCommands.Throw || command == CharacterCommands.LowThrow) { if(ActionState != HumanActionStates.None) { return; } if(_thrownObjectInHand == null) { DrawNextGrenade(); } MyAimIK.solver.SmoothDisable(15); if(command == CharacterCommands.LowThrow) { MyAnimator.SetTrigger("LowThrow"); _isLowThrow = true; } else { MyAnimator.SetTrigger("Throw"); _isLowThrow = false; } _throwTarget = this.AimPoint; Quaternion rotation = Quaternion.LookRotation(this.AimPoint - transform.position); transform.rotation = rotation; IsBodyLocked = true; Debug.Log("Throw triggered"); } if(command == CharacterCommands.ThrowGrenade) { if(ActionState != HumanActionStates.None) { return; } if(UpperBodyState != HumanUpperBodyStates.Aim) { //MyAimIK.solver.transform = this.MyReference.TorsoWeaponMount.transform; } SendCommand(CharacterCommands.CancelReload); if(this.MyReference.CurrentWeapon != null && MyAnimator.GetInteger("WeaponType") == (int)WeaponAnimType.Longgun) { MyLeftHandIK.SmoothEnable(); } //MyHeadIK.SmoothDisable(1); //move weapon to torso mount so that right hand is free if(this.MyReference.CurrentWeapon != null) { this.MyReference.CurrentWeapon.transform.parent = this.MyReference.TorsoWeaponMount.transform; } MyAnimator.SetTrigger("ThrowGrenade"); _throwTarget = this.AimPoint; _throwDir = this.AimPoint - transform.position; IsBodyLocked = true; Quaternion rotation = Quaternion.LookRotation(new Vector3(_throwDir.x, 0, _throwDir.z)); transform.rotation = rotation; ActionState = HumanActionStates.Throw; _thrownObjectInHand = ((GameObject)GameObject.Instantiate(Resources.Load("PipeGrenade"))).GetComponent<ThrownObject>(); Explosive explosive = _thrownObjectInHand.GetComponent<Explosive>(); if(explosive != null) { explosive.Attacker = this; } _thrownObjectInHand.GetComponent<Rigidbody>().isKinematic = true; _thrownObjectInHand.transform.parent = this.MyReference.RightHandWeaponMount.transform; _thrownObjectInHand.transform.localPosition = _thrownObjectInHand.InHandPosition; _thrownObjectInHand.transform.localEulerAngles = _thrownObjectInHand.InHandRotation; } if(command == CharacterCommands.UseTool) { if(ActionState != HumanActionStates.None || MyAI.BlackBoard.TargetEnemy == null) { return; } //check if the target enemy is close enough and angle between character and enemy is less than 45 if(Vector3.Distance(MyAI.BlackBoard.TargetEnemy.transform.position, transform.position) > 2 || Vector3.Angle(MyAI.BlackBoard.TargetEnemy.transform.forward, transform.forward) > 45) { return; } Vector3 lineOfSight = MyAI.BlackBoard.TargetEnemy.transform.position - transform.position; //check if angle between character facing and target line of sight is less than 45 if(Vector3.Angle(lineOfSight, transform.forward) > 45) { return; } //stop movement SendCommand(CharacterCommands.Idle); IsBodyLocked = true; MyNavAgent.enabled = false; //place player right behind target transform.position = MyAI.BlackBoard.TargetEnemy.transform.position - lineOfSight.normalized * 0.25f; //align player facing direction to enemy's lineOfSight = new Vector3(lineOfSight.x, 0, lineOfSight.z); Quaternion rotation = Quaternion.LookRotation(lineOfSight); transform.rotation = rotation; MyAnimator.SetTrigger("Strangle"); _strangleTarget = MyAI.BlackBoard.TargetEnemy; SendCommand(CharacterCommands.StopAim); ActionState = HumanActionStates.Strangle; } if(command == CharacterCommands.Pickup) { if(ActionState != HumanActionStates.None || MyAI.BlackBoard.PickupTarget == null) { return; } //move weapon to torso mount so that right hand is free if(this.MyReference.CurrentWeapon != null && MyAnimator.GetInteger("WeaponType") == (int)WeaponAnimType.Longgun) { this.MyReference.CurrentWeapon.transform.parent = this.MyReference.TorsoWeaponMount.transform; } MyAnimator.SetTrigger("TakeObject"); } if(command == CharacterCommands.Loot) { if(ActionState != HumanActionStates.None) { return; } GameObject useTarget = MyAI.BlackBoard.UseTarget; Character target = MyAI.BlackBoard.InteractTarget; if(target != null && target.MyStatus.Health <= 0) { if(this.MyAI.ControlType == AIControlType.Player) { UIEventHandler.Instance.TriggerLootBody(); } } else if(useTarget != null) { //open chest Chest chest = useTarget.GetComponent<Chest>(); if(chest != null) { //open UI UIEventHandler.Instance.TriggerLootChest(); } } } if(command == CharacterCommands.Talk) { if(ActionState != HumanActionStates.None) { return; } Debug.Log("opening dialog"); Character target = MyAI.BlackBoard.InteractTarget; if(target != null && target.MyStatus.Health > 0) { if(this.MyAI.ControlType == AIControlType.Player) { UIEventHandler.Instance.TriggerDialogue(); } } } if(command == CharacterCommands.SetAlert) { float ambient = RenderSettings.ambientIntensity; if(MyAI.BlackBoard.GuardLevel == 1) { //weapon holstered; only turn on flash light (if has one) when completely dark if(MyReference.CurrentWeapon != null) { SendCommand(CharacterCommands.Unarm); } if(MyReference.Flashlight != null) { if(ambient <= 0.3f) { MyReference.Flashlight.Toggle(true); } else { MyReference.Flashlight.Toggle(false); } } } else if(MyAI.BlackBoard.GuardLevel >= 2) { if(MyReference.CurrentWeapon == null) { SendCommand(MyAI.WeaponSystem.GetBestWeaponChoice()); } if(MyReference.Flashlight != null) { if(ambient <= 0.5f) { MyReference.Flashlight.Toggle(true); } else { MyReference.Flashlight.Toggle(false); } } } } }