// Basically there are two options for now, look where you're going, or look at the player. // This function has no side effects. And should never have side effects. We simply return a quaternion that we think the enemy // should have as it's orientation. Nothing more. public Quaternion OrientModel(AI_Conditions conResults, Vector3 vel, Vector3 ourPos, Vector3 goalPos) { Vector3 mvDir; Vector3 plyDir; // Get rid of any y rotation, for now. mvDir = vel; mvDir.y = 0; mvDir = Vector3.Normalize(mvDir); plyDir = goalPos - ourPos; plyDir.y = 0; plyDir = Vector3.Normalize(plyDir); Quaternion faceVel = Quaternion.LookRotation(mvDir); Quaternion facePly = Quaternion.LookRotation(plyDir); // If we can't see the player, face where we're going if (!conResults.mCanSeePlayer) { return(faceVel); } if (conResults.mWithinGunRange) { return(facePly); } return(faceVel); }
private void Awake() { mEntity = GetComponent <AI_Controller>(); mCons = GetComponent <AI_Conditions>(); mOrienter = GetComponent <AI_Orienter>(); mStrafer = GetComponent <AI_Strafer>(); mGun = GetComponentInChildren <WP_Gun>(); mRigid = GetComponent <Rigidbody>(); mAnim = UT_FindComponent.FindComponent <AN_Enemies>(gameObject); }
// so here we have to kind of hack in figuring out when we last shot, and if it's this frame (or very close to) private void SetShotTrigger() { AI_Conditions cons = mEntity.GetComponent <AI_Conditions>(); if (Time.time - mGun.mFireTimeStamp <= 0.05f) { mAnimController.SetTrigger("Shoot"); } else { mAnimController.ResetTrigger("Shoot"); } }
public override void DrawNode() { GUILayout.BeginHorizontal(); GUILayoutOption op = GUILayout.MinWidth(300); Condition = (AI_Conditions)EditorGUILayout.EnumPopup("Condition : ", Condition, op); // From Linker Node if (Event.current.type == EventType.Repaint) { if (Linkers[(int)Node.LinkType.From]) { Linkers[(int)Node.LinkType.From].SetRect(new Rect( rect.x + rect.width / 2, rect.y - 16, 16, 16 )); } } // ToKO Linker Node if (Event.current.type == EventType.Repaint) { if (Linkers[(int)Node.LinkType.ToKO]) { Linkers[(int)Node.LinkType.ToKO].SetRect(new Rect( rect.x + rect.width / 4, rect.y + rect.height, 16, 16 )); } } // ToOK Linker Node if (Event.current.type == EventType.Repaint) { if (Linkers[(int)Node.LinkType.ToOK]) { Linkers[(int)Node.LinkType.ToOK].SetRect(new Rect( rect.x + rect.width / 4 + rect.width / 2, rect.y + rect.height, 16, 16 )); } } GUILayout.EndHorizontal(); ConditionFunction.DrawGUI(); if (GUI.changed) { Node_Editor.editor.RecalculateFrom(this); if (oldCondition != Condition) { var type = System.Type.GetType(AI_ConditionsDico[(int)Condition]); ConditionFunction = (ConditionNodeFunctions)System.Activator.CreateInstance(type); oldCondition = Condition; } } }