public ElectricState(Player player, StateMachine <Player> fsm, ElectricNavpoint entry) : base(player, fsm) { previousNode = entry; nextNode = entry.getFirstNavPoint(); selfBody = player.GetComponent <Rigidbody>(); selfCollider = Owner.GetComponentInChildren <Collider>(); }
void Start() { eNavPoint = this.transform.parent.GetComponent <ElectricNavpoint>(); if (eNavPoint == null) { Debug.LogWarning("Cannot find the ElectricNavpoint script on this object! Deleting self."); Destroy(this.gameObject); } }
public ElectricState(Player player, StateMachine <Player> fsm, ElectricNavpoint entry) : base(player, fsm) { previousNode = entry; nextNode = entry.getFirstNavPoint(); selfBody = player.GetComponent <Rigidbody>(); transparentObj = GameObject.FindObjectsOfType <TurnTransparent>(); entry.Trigger(); }
public ElectricNavpoint getNextNavPoint(Vector3 direction) { if (direction != Vector3.zero) { ElectricNavpoint nextNavPoint = adjacentPoints.Aggregate( (nav1, nav2) => Vector3.Angle(nav1.transform.position - gameObject.transform.position, direction) < Vector3.Angle(nav2.transform.position - gameObject.transform.position, direction) ? nav1 : nav2); return(nextNavPoint); } else { return(adjacentPoints[0]); } }
override public void Execute() { targetVelocity = StaticMovementAlgorithms.KinematicArrive(selfBody, nextNode.transform.position, ELECTRIC_SPEED, ARRIVE_RADIUS); /* * if (Controls.getDirection() != Vector3.zero) * { * Debug.Log("Controller decided"); * Debug.DrawLine(nextNode.transform.position, nextNode.getNextNavPoint(Controls.getDirection()).transform.position); * } * else * { * Debug.Log("Velocity Decided"); * Debug.DrawLine(nextNode.transform.position, nextNode.getNextNavPoint(selfBody.velocity).transform.position); * } */ if (targetVelocity == Vector3.zero) { if (nextNode.isEndpoint) { Owner.ActionFsm.ChangeState(new IdleState(Owner, Owner.ActionFsm)); } else { ElectricNavpoint nextNodeCandidate; Vector3 input_direction = Controls.getDirection(); if (input_direction != Vector3.zero && Owner.stamina > 0.0f) { nextNodeCandidate = nextNode.getNextNavPoint(input_direction, previousNode); if (nextNodeCandidate == previousNode) { nextNodeCandidate = nextNode.getNextNavPoint(selfBody.velocity, previousNode); } } else { nextNodeCandidate = nextNode.getNextNavPoint(selfBody.velocity, previousNode); } previousNode = nextNode; nextNode = nextNodeCandidate; //Now we trigger any associated devices previousNode.Trigger(); } } Owner.UseStamina(STAMINA_COST_PER_SECOND * Time.deltaTime); }
override public void Execute() { targetVelocity = StaticMovementAlgorithms.KinematicArrive(selfBody, nextNode.transform.position, ELECTRIC_SPEED, ARRIVE_RADIUS); /* * if (Controls.getDirection() != Vector3.zero) * { * Debug.Log("Controller decided"); * Debug.DrawLine(nextNode.transform.position, nextNode.getNextNavPoint(Controls.getDirection()).transform.position); * } * else * { * Debug.Log("Velocity Decided"); * Debug.DrawLine(nextNode.transform.position, nextNode.getNextNavPoint(selfBody.velocity).transform.position); * } */ if (targetVelocity == Vector3.zero) { if (nextNode.isEndpoint) { Owner.ActionFsm.ChangeState(new IdleState(Owner, Owner.ActionFsm)); } else { ElectricNavpoint nextNodeCandidate; Vector3 input_direction = Controls.getDirection(); if (input_direction != Vector3.zero) { nextNodeCandidate = nextNode.getNextNavPoint(input_direction); if (nextNodeCandidate == previousNode) { nextNodeCandidate = nextNode.getNextNavPoint(selfBody.velocity); } } else { nextNodeCandidate = nextNode.getNextNavPoint(selfBody.velocity); } previousNode = nextNode; nextNode = nextNodeCandidate; } } }
public ElectricNavpoint getNextNavPoint(Vector3 direction, ElectricNavpoint previousNode = null) { if (direction != Vector3.zero) { ElectricNavpoint nextNavPoint = adjacentPoints.Aggregate( (nav1, nav2) => { float angle1 = nav1 != previousNode ? Vector3.Angle(nav1.transform.position - gameObject.transform.position, direction) : float.PositiveInfinity; float angle2 = nav2 != previousNode ? Vector3.Angle(nav2.transform.position - gameObject.transform.position, direction) : float.PositiveInfinity; return(angle1 < angle2 ? nav1 : nav2); }); return(nextNavPoint); } else { return(adjacentPoints[0]); } }
public void TurnToElectricCurrent(ElectricNavpoint entryPoint) { this.UseStamina(TRANSFORM_TO_CURRENT_COST); this.ActionFsm.ChangeState(new ElectricState(this, this.ActionFsm, entryPoint)); }