public BehaviorReturnCode WalkTransition(Edge actualEdge) { if (actualEdge.TransType.Equals(TransitionType.WALK)) { if (State.Equals(WorkState.Idle)) { State = WorkState.Running_WALK; CalculateDirection(actualEdge); targetPosition = new Vector2(RoundedMath.Mult(actualEdge.Target.X, 3.1f), RoundedMath.Mult(actualEdge.Target.Y, 3.1f)); TimeLimit = Time.time + (Vector3.Distance(transform.position, targetPosition) / 20) + 1f; walkToPosition = true; walk = 1; return(BehaviorReturnCode.Running); } else if (State == WorkState.Finished) { State = WorkState.Idle; if (Mathf.Abs(transform.position.y - targetPosition.y) < 5f) { return(BehaviorReturnCode.Success); } return(BehaviorReturnCode.Failure); } else if (State == WorkState.Running_WALK && movementController.Moving() && Time.time <= TimeLimit) { return(BehaviorReturnCode.Running); } KillMovement(); return(BehaviorReturnCode.Failure); } else { return(BehaviorReturnCode.Failure); } }
private void ResetPosition() { if (Time.time >= nextValidReset) { nextValidReset = Time.time + 0.5f; transform.position = new Vector3(RoundedMath.Mult(Mathf.RoundToInt(transform.position.x / 3.1f), 3.1f), transform.position.y); } }
IEnumerator _PortTo(Edge actualEdge) { Debug.Log("I'm porting!"); yield return(new WaitForSeconds(1)); transform.position = new Vector2(RoundedMath.Mult(actualEdge.Target.X, 3.1f), RoundedMath.Mult(actualEdge.Target.Y, 3.1f) + 1.55f); transform.GetComponent <Rigidbody2D>().velocity = Vector2.zero; Debug.Log("Ported :D I'm so awesome!"); State = WorkState.Finished; }
public void SetupAI(AISettings settings) { aiEnabled = false; this.maxLP = settings.MaxLP; this.minimumDistance = settings.MinDistance; GetComponent <AIWeaponController>().accuracy = settings.Accuracy; GetComponent <AIWeaponController>().cooldown = settings.CoolDown; GetComponent <AIWeaponController>().maxExtraCooldown = settings.MaxExtraCooldown; GetComponent <AIWeaponController>().shootDistance = settings.ShootDistance; GetComponent <AIWeaponController>().Setup(); if (target == null) { GameObject go = GameObject.FindGameObjectWithTag(enemyTag); if (go != null) { target = go.transform; } } lp = maxLP; this.transform.position = new Vector3(RoundedMath.Mult(Mathf.RoundToInt(this.transform.position.x / boxFactor), boxFactor), this.transform.position.y); aiMovement = GetComponent <AIMovement>(); aiWeaponController = GetComponent <AIWeaponController>(); ea = new EnvironmentAnalyser(); aiMemory = new AIMemory(windowSizeX, windowSizeY, this.transform.position, ea, this, boxFactor); generalSolver = new GeneralSolver(aiMemory); aiMemory.MaxAreaWidth = settings.MaxAreaWidth; aiToTarget = new AIGetToTargetActions(aiMemory, generalSolver, aiMovement, this.transform, target, this, minimumDistance, this); aiWeaponActions = new AIWeaponActions(aiWeaponController); projectileDetector = new ProjectileDetector(this.transform, 10, projectileLayer); aiBehaviorTree = new AIBehaviorTree(aiToTarget, aiWeaponActions, this, projectileDetector); if (aiType == AIType.AGGRESSIVE) { aiBehaviorTree.CreateAndStartAggrassiveAI(); } if (aiType == AIType.DEFENSIVE) { aiBehaviorTree.CreateAndStartDefensiveAI(); } aiEnabled = true; }
public BehaviorReturnCode FallTransition(Edge actualEdge) { if (actualEdge.TransType.Equals(TransitionType.FALL) || actualEdge.TransType.Equals(TransitionType.JUMP_DOWN)) { if (State == WorkState.Idle) { State = WorkState.Running_FALL; CalculateDirection(actualEdge); targetPosition = new Vector2(RoundedMath.Mult(actualEdge.Target.X, 3.1f), RoundedMath.Mult(actualEdge.Target.Y, 3.1f)); TimeLimit = Time.time + (Vector3.Distance(transform.position, targetPosition) / 20) + 2f; if (actualEdge.TransType.Equals(TransitionType.FALL)) { walkToPosition = true; walk = 1; } else { walkToPosition = true; walk = 1; PushAI(); Jump(); } return(BehaviorReturnCode.Running); } else if (State == WorkState.Finished) { State = WorkState.Idle; onJump = false; return(BehaviorReturnCode.Success); } else if (State == WorkState.Running_FALL && Time.time <= TimeLimit) { return(BehaviorReturnCode.Running); } KillMovement(); return(BehaviorReturnCode.Failure); } else { return(BehaviorReturnCode.Failure); } }
void OnPostRender() { CreateLineMaterial(); lineMaterial.SetPass(0); GL.Begin(GL.LINES); if (aiMapGraph != null) { foreach (Node node in aiMapGraph.AllNodes) { Vector3 nodeV = new Vector3(RoundedMath.Mult(node.X, 3.1f), RoundedMath.Mult(node.Y, 3.1f)); GL.Color(Color.black); GL.Vertex(nodeV + new Vector3(0, 1)); GL.Vertex(nodeV + new Vector3(0, -1)); if (node.EdgesOut != null) { foreach (Edge e in node.EdgesOut) { Vector3 additional = new Vector3(0, 1f); if (e.Source.X < e.Target.X) { additional *= -1; } Vector3 start2 = new Vector3(RoundedMath.Mult(e.Source.X, 3.1f), RoundedMath.Mult(e.Source.Y, 3.1f)); Vector3 end2 = new Vector3(RoundedMath.Mult(e.Target.X, 3.1f), RoundedMath.Mult(e.Target.Y, 3.1f)); if (e.TransType == TransitionType.JUMP) { GL.Color(Color.red); GL.Vertex(start2 + additional); GL.Vertex(end2 + additional); } else if (e.TransType == TransitionType.WALK) { GL.Color(Color.blue); GL.Vertex(start2 + additional * 0.25f); GL.Vertex(end2 + additional * 0.25f); } else if (e.TransType == TransitionType.FALL) { GL.Color(Color.yellow); GL.Vertex(start2 + additional); GL.Vertex(end2 + additional); } else { GL.Color(Color.black); GL.Vertex(start2 + additional); GL.Vertex(end2 + additional); } } } } foreach (PlatformArea area in aiMapGraph.AllAreas) { Vector3 start = new Vector3(RoundedMath.Mult(area.XLeft, 3.1f) - 0.55f, RoundedMath.Mult(area.YBottom, 3.1f) - 1.55f); Vector3 end = new Vector3(RoundedMath.Mult(area.XRight, 3.1f) + 0.55f, RoundedMath.Mult(area.YBottom, 3.1f) - 1.55f); GL.Color(Color.green); GL.Vertex(start); GL.Vertex(end); } if (Path.Count > 0) { GL.Color(Color.green); GL.Vertex(new Vector3(aiMapGraph.MultWithBoxFactor(source.X), aiMapGraph.MultWithBoxFactor(source.Y))); foreach (AStarNode n in Path) { Vector3 point = new Vector3(aiMapGraph.MultWithBoxFactor(n.X), aiMapGraph.MultWithBoxFactor(n.Y)); GL.Vertex(point); GL.Vertex(point); } GL.Vertex(new Vector3(aiMapGraph.MultWithBoxFactor(Path.Last.Value.X), aiMapGraph.MultWithBoxFactor(Path.Last.Value.Y))); } } GL.End(); }
private void SetLateJump() { jump = true; jumpPosition = RoundedMath.Mult(Mathf.RoundToInt(this.transform.position.x / 3.1f), 3.1f) + (direction * 1.5f); }
public BehaviorReturnCode JumpTransition(Edge actualEdge) { if (actualEdge.TransType.Equals(TransitionType.JUMP)) { if (State == WorkState.Idle) { State = WorkState.Running_JUMP; CalculateDirection(actualEdge); targetPosition = new Vector2(RoundedMath.Mult(actualEdge.Target.X, 3.1f), RoundedMath.Mult(actualEdge.Target.Y, 3.1f)); TimeLimit = Time.time + (Vector3.Distance(transform.position, targetPosition) / 20) + 2f; if (Mathf.Abs(actualEdge.Source.X - actualEdge.Target.X) <= 1f) { ResetPosition(); Jump(); walkInHight = true; } else if (Mathf.Abs(actualEdge.Source.X - actualEdge.Target.X) <= 2f) { if (Mathf.Abs(actualEdge.Source.Y - actualEdge.Target.Y) <= 3f) { ResetPosition(); walkToPosition = true; walk = 1; PushAI(); Jump(); } else { ResetPosition(); Jump(); walkInHight = true; } } else if (CanYouJumpThis(new Vector2(actualEdge.Source.X, actualEdge.Source.Y), new Vector2(actualEdge.Target.X, actualEdge.Target.Y))) { //ResetPosition(); walkToPosition = true; walk = 1; PushAI(); SetLateJump(); } return(BehaviorReturnCode.Running); } else if (State == WorkState.Finished) { State = WorkState.Idle; onJump = false; if (Mathf.Abs(transform.position.x - targetPosition.x) > 1f) { return(BehaviorReturnCode.Failure); } return(BehaviorReturnCode.Success); } else if (State == WorkState.Running_JUMP && Time.time <= TimeLimit) { return(BehaviorReturnCode.Running); } KillMovement(); return(BehaviorReturnCode.Failure); } else { return(BehaviorReturnCode.Failure); } }
/// <summary> /// Multipliziert einen int mit der Blockbreite. /// (Rückrechnung von Array Koordinaten in reale Koordinaten) /// </summary> /// <param name="a"></param> /// <returns>float * boxFactor</returns> public float MultWithBoxFactor(int a) { return(RoundedMath.Mult(a, boxFactor)); }