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(); }
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); }