/*private void ActionRotate(Vector3 direction) * { * RotateAction = AgentActionFactory.Create(AgentActionFactory.E_Type.Rotate) as AgentActionRotate; * RotateAction.Direction = direction; * Owner.BlackBoard.AddAction(RotateAction); * }*/ private void SendAction() { Fact fact = Owner.Memory.GetFact(Query); if (fact != null) { Action = AgentActionFactory.Create(AgentActionFactory.E_Type.Rotate) as AgentActionRotate; Action.Target = fact.Agent; Action.RotationModifier = 0.8f; Owner.BlackBoard.AddAction(Action); //if (Owner.debugGOAP) Debug.Log(this.ToString() + " - " + Action.Target.GameObject.ToString()); } else if (Owner.BlackBoard.DesiredTarget != null) { Action = AgentActionFactory.Create(AgentActionFactory.E_Type.Rotate) as AgentActionRotate; Action.Target = Owner.BlackBoard.DesiredTarget; Action.RotationModifier = 0.5f; Owner.BlackBoard.AddAction(Action); //if (Owner.debugGOAP) Debug.Log(this.ToString() + " - " + Action.Target.GameObject.ToString()); } //UnityEngine.Debug.Log(this.ToString() + "Send new goto action to pos " + FinalPos.ToString()); }
public override void Reset() { if (Owner.BlackBoard.AimAnimationsEnabled) { Animation[AnimNameUp].weight = 0; Animation[AnimNameDown].weight = 0; Animation.Stop(AnimNameUp); Animation.Stop(AnimNameDown); } if (WeaponAction != null) { WeaponAction.SetSuccess(); WeaponAction = null; } if (RotateAction != null) { RotateAction.SetSuccess(); RotateAction = null; } InstantBlend = true; base.Reset(); }
public override void Update() { if (WeaponAction != null && TimeToFinishWeaponAction < Time.timeSinceLevelLoad) { WeaponAction.SetSuccess(); WeaponAction = null; //Debug.Log(Owner.AnimSet.GetIdleAnim(Owner.BlackBoard.WeaponSelected, Owner.BlackBoard.WeaponState).ToString()); //PlayIdleAnim(); CrossFade(Owner.AnimSet.GetIdleAnim(), 0.4f, PlayMode.StopSameLayer); } if (RotateAction != null && TimeToFinishRotateAction < Time.timeSinceLevelLoad) { RotateAction.SetSuccess(); RotateAction = null; } //fall down if not grounded if (Owner.IsInCover == false) { Move(Vector3.zero, false); } PlayIdleAnim(); if (Owner.BlackBoard.AimAnimationsEnabled && Owner.IsInCover == false) { UpdateBlendValues(); UpdateBlendedAnims(); } }
override public void OnDeactivate() { // Time.timeScale = 1; //AnimEngine.Stop(AnimName); Action.SetSuccess(); Action = null; base.OnDeactivate(); }
protected override void Initialize(AgentAction action) { base.Initialize(action); Action = action as AgentActionRotate; CurrentRotationTime = 0; StartRotation = Transform.rotation; Vector3 finalDir; if (Action.Target != null) { finalDir = (Action.Target.Position + (Action.Target.BlackBoard.MoveDir * Action.Target.BlackBoard.Speed * 0.5f)) - Transform.position; finalDir.Normalize(); } else if (Action.Direction != Vector3.zero) { finalDir = Action.Direction; } else { finalDir = Transform.forward; } if (Vector3.Dot(finalDir, Transform.right) > 0) { AnimName = Owner.AnimSet.GetRotateAnim(Owner.BlackBoard.MotionType, E_RotationType.Right); } else { AnimName = Owner.AnimSet.GetRotateAnim(Owner.BlackBoard.MotionType, E_RotationType.Left); } CrossFade(AnimName, 0.01f); FinalRotation.SetLookRotation(finalDir); RotationTime = Vector3.Angle(Transform.forward, finalDir) / (360.0f * Owner.BlackBoard.RotationSmooth); if (RotationTime == 0) { Release(); } float animLen = AnimEngine[AnimName].length; int steps = Mathf.CeilToInt(RotationTime / animLen); EndOfStateTime = AnimEngine[AnimName].length * steps + Time.timeSinceLevelLoad; //Debug.Log(steps + " " + RotationTime + " " + AnimEngine[AnimName].length); }
public override void OnDeactivate() { if (WeaponAction != null) { WeaponAction.SetSuccess(); WeaponAction = null; } if (RotateAction != null) { RotateAction.SetSuccess(); RotateAction = null; } base.OnDeactivate(); }
// Update is called once per frame void Update() { if (Owner.IsAlive == false) { RotattionDiff = 0; return; } //Profiler.BeginSample ("ComponentBody.Update() : Main part"); if (Owner.IsInCover && Owner.IsLeavingToCover == false) { FinalRotation.eulerAngles = new Vector3(0, Owner.BlackBoard.Cover.Transform.rotation.eulerAngles.y, 0); if (Time.deltaTime > Mathf.Epsilon) { Owner.Transform.rotation = Quaternion.Lerp(Owner.Transform.rotation, FinalRotation, RotationSpeed * Time.deltaTime * 5); } CheckEdges(); } else if (Owner.IsInKnockdown) { RotattionDiff = 0; if (Owner.IsProxy) { // Server changes the player rotation during knockdown, we have to follow it, not ignore it FinalRotation.eulerAngles = new Vector3(0, Owner.BlackBoard.Desires.Rotation.eulerAngles.y, 0); if (Time.deltaTime > Mathf.Epsilon) { Owner.Transform.rotation = Quaternion.Lerp(Owner.Transform.rotation, FinalRotation, RotationSpeed * Time.deltaTime); } } } else { if (ActionRotate == null && Owner.IsServer == false) { float diff = Owner.Transform.rotation.eulerAngles.y - Owner.BlackBoard.Desires.Rotation.eulerAngles.y; if (diff < 0.001f && diff > -0.001f) { //clamp small numbers otherwise RotationDiff is being incremented for a long time if Desire and Owner rotation is not EXACTLY the same! diff = 0; } if (diff > 180) { diff -= 360; } else if (diff < -180) { diff += 360; } if (diff == 0) { RotattionDiff = 0; } else { RotattionDiff += Mathf.Abs(diff); } if (RotattionDiff > 10) { ActionRotate = AgentActionFactory.Create(AgentActionFactory.E_Type.Rotate) as AgentActionRotate; ActionRotate.Rotation = diff > 0 ? E_RotationType.Left : E_RotationType.Right; Owner.BlackBoard.ActionAdd(ActionRotate); RotattionDiff = 0; } } FinalRotation.eulerAngles = new Vector3(0, Owner.BlackBoard.Desires.Rotation.eulerAngles.y, 0); //if( !Owner.IsProxy ) if (!Owner.IsServer) // rotation on server is driven by ServerUpdate() { if (Time.deltaTime > Mathf.Epsilon) { Owner.Transform.rotation = Quaternion.Lerp(Owner.Transform.rotation, FinalRotation, RotationSpeed * Time.deltaTime); //Owner.Transform.rotation = Owner.BlackBoard.Desires.Rotation; } } } //Profiler.EndSample(); //Profiler.BeginSample ("ComponentBody.Update() : UpdateAiming"); UpdateAiming(); //Profiler.EndSample(); if (ActionRotate != null && ActionRotate.IsActive() == false) { ActionRotate = null; } HandleMovement(); }
static public AgentAction Create(E_Type type) { int index = (int)type; AgentAction a; if (m_UnusedActions[index].Count > 0) { a = m_UnusedActions[index].Dequeue(); } else { switch (type) { case E_Type.E_IDLE: a = new AgentActionIdle(); break; case E_Type.E_MOVE: a = new AgentActionMove(); break; case E_Type.E_GOTO: a = new AgentActionGoTo(); break; case E_Type.E_COMBAT_MOVE: a = new AgentActioCombatMove(); break; case E_Type.E_ATTACK: a = new AgentActionAttack(); break; case E_Type.E_ATTACK_ROLL: a = new AgentActionAttackRoll(); break; case E_Type.E_ATTACK_WHIRL: a = new AgentActionAttackWhirl(); break; case E_Type.E_INJURY: a = new AgentActionInjury(); break; case E_Type.E_DAMAGE_BLOCKED: a = new AgentActionDamageBlocked(); break; case E_Type.E_BLOCK: a = new AgentActionBlock(); break; case E_Type.E_ROLL: a = new AgentActionRoll(); break; case E_Type.E_INCOMMING_ATTACK: a = new AgentActionIncommingAttack(); break; case E_Type.E_WEAPON_SHOW: a = new AgentActionWeaponShow(); break; case E_Type.Rotate: a = new AgentActionRotate(); break; case E_Type.E_USE_LEVER: a = new AgentActionUseLever(); break; case E_Type.E_PLAY_ANIM: a = new AgentActionPlayAnim(); break; case E_Type.E_PLAY_IDLE_ANIM: a = new AgentActionPlayIdleAnim(); break; case E_Type.E_DEATH: a = new AgentActionDeath(); break; case E_Type.E_KNOCKDOWN: a = new AgentActionKnockdown(); break; case E_Type.Teleport: a = new AgentActionTeleport(); break; default: Debug.LogError("no AgentAction to create"); return(null); } } a.Reset(); a.SetActive(); // DEBUG !!!!!! m_ActionsInAction.Add(a); return(a); }
public override bool HandleNewAction(AgentAction action) { //if (m_Human.PlayerProperty != null) //if(Owner.debugAnims) Debug.Log(Time.timeSinceLevelLoad + " " + this.ToString() + " - action " + action.ToString()); if (action is AgentActionIdle) { action.SetFailed(); return(true); } else if (action is AgentActionAttack) { if (null != Owner.AnimSet) { string s = Owner.AnimSet.GetWeaponAnim(E_WeaponAction.Fire); if (null != s) { AnimationState state = Animation[s]; if (null != state) { TimeToFinishWeaponAction = Time.timeSinceLevelLoad + state.length * 0.5f; state.layer = 2; state.blendMode = AnimationBlendMode.Additive; if (Animation.IsPlaying(s)) { //Debug.Log(Time.timeSinceLevelLoad + " " + s + " rewind " + Animation[s].length + " " + Animation[s].time); state.time = 0; } else { //Debug.Log(Time.timeSinceLevelLoad + " " + s + " fade " + Animation[s].length + " " + Animation[s].time); Blend(s, 0.05f); } } } } if (WeaponAction != null) { WeaponAction.SetSuccess(); } WeaponAction = action; return(true); } else if (action is AgentActionInjury) { PlayInjuryAnimation(action as AgentActionInjury); return(true); } else if (action is AgentActionReload) { if (null != Owner.AnimSet) { string s = Owner.AnimSet.GetWeaponAnim(E_WeaponAction.Reload); if (null != s) { AnimationState state = Animation[s]; if (null != state) { state.layer = 2; state.blendMode = AnimationBlendMode.Blend; Blend(s, 0.2f); TimeToFinishWeaponAction = Time.timeSinceLevelLoad + state.length - 0.3f; } } action.SetSuccess(); WeaponAction = action; // PrevBlendUp *= 0.25f; //this is to minimize the quick blend to aim after reload // PrevBlendDown *= 0.25f; } return(true); } else if (action is AgentActionRotate) { RotateAction = action as AgentActionRotate; if (null != Owner.AnimSet) { string s = Owner.AnimSet.GetRotateAnim(RotateAction.Rotation); if (s != null && Animation.IsPlaying(s) == false) { /* if ( Animation[s] == null ) * { * Debug.Log ("Animation.Length=" + Animation.GetClipCount() + ", agent=" + Owner.name); * * foreach ( AnimationClip clip in Animation ) * Debug.Log ("clip=" + clip.name ); * } */ AnimationState state = Animation[s]; if (null != state) { state.blendMode = AnimationBlendMode.Additive; state.layer = 1; TimeToFinishRotateAction = Time.timeSinceLevelLoad + state.length + 0.3f; Blend(s, 0.1f); } } } } return(false); }
public static AgentAction Create(E_Type type) { int index = (int)type; AgentAction a; if (m_UnusedActions[index].Count > 0) { a = m_UnusedActions[index].Dequeue(); } else { switch (type) { case E_Type.Idle: a = new AgentActionIdle(); break; case E_Type.Move: a = new AgentActionMove(); break; case E_Type.Sprint: a = new AgentActionSprint(); break; case E_Type.Goto: a = new AgentActionGoTo(); break; case E_Type.Attack: a = new AgentActionAttack(); break; case E_Type.Melee: a = new AgentActionMelee(); break; case E_Type.Injury: a = new AgentActionInjury(); break; case E_Type.Roll: a = new AgentActionRoll(); break; case E_Type.WeaponChange: a = new AgentActionWeaponChange(); break; case E_Type.Rotate: a = new AgentActionRotate(); break; case E_Type.Use: a = new AgentActionUse(); break; case E_Type.PlayAnim: a = new AgentActionPlayAnim(); break; case E_Type.PlayIdleAnim: a = new AgentActionPlayIdleAnim(); break; case E_Type.Death: a = new AgentActionDeath(); break; case E_Type.Knockdown: a = new AgentActionKnockdown(); break; case E_Type.Teleport: a = new AgentActionTeleport(); break; case E_Type.CoverEnter: a = new AgentActionCoverEnter(); break; case E_Type.CoverMove: a = new AgentActionCoverMove(); break; case E_Type.CoverFire: a = new AgentActionCoverFire(); break; case E_Type.CoverFireCancel: a = new AgentActionCoverFireCancel(); break; case E_Type.CoverLeave: a = new AgentActionCoverLeave(); break; case E_Type.Reload: a = new AgentActionReload(); break; case E_Type.UseItem: a = new AgentActionUseItem(); break; case E_Type.ConstructGadget: a = new AgentActionConstructGadget(); break; case E_Type.TeamCommand: a = new AgentActionTeamCommand(); break; default: Debug.LogError("no AgentAction to create"); return(null); } } a.Reset(); a.SetActive(); // DEBUG !!!!!! // m_ActionsInAction.Add(a); return(a); }