private void Update() { float yaxis = 0f; if(_currentCommand != null) { _timeOut -= Time.deltaTime; if(_timeOut < 0f) { Debug.Log ("Command timed out."); _currentCommand = null; return; } float dot = Vector3.Dot(transform.right, _targetForward); if(_currentCommand.Command == AngieCommand.CommandType.TURN_MINUS_90) { if(dot < 0f) transform.Rotate(0f, Time.deltaTime * -_rotationSpeed, 0f); else _currentCommand = null; } else if(_currentCommand.Command == AngieCommand.CommandType.TURN_PLUS_90) { if(dot > 0f) transform.Rotate(0f, Time.deltaTime * _rotationSpeed, 0f); else _currentCommand = null; } else if( _currentCommand.Command == AngieCommand.CommandType.FWD_1M || _currentCommand.Command == AngieCommand.CommandType.FWD_5M || _currentCommand.Command == AngieCommand.CommandType.BACK_1M ) { if(_currentCommand.Command == AngieCommand.CommandType.BACK_1M) yaxis = -1f; else yaxis = 1f; float dis = Vector3.Distance( transform.position, _targetPosition); if(_previousTargetDistance > 0f && _previousTargetDistance < dis) _currentCommand = null; else _previousTargetDistance = dis; } } else if(_queue.Count > 0) { _timeOut = 10.0f; _currentCommand = _queue.Dequeue(); Debug.Log("Dequeueing " + _currentCommand.Command); _targetPosition = transform.position; _previousTargetDistance = 0f; if(_currentCommand.Command == AngieCommand.CommandType.TURN_MINUS_90) { _targetForward = new Vector3( -transform.right.x, -transform.right.y, -transform.right.z); } else if(_currentCommand.Command == AngieCommand.CommandType.TURN_PLUS_90) { _targetForward = new Vector3( transform.right.x, transform.right.y, transform.right.z); } else if(_currentCommand.Command == AngieCommand.CommandType.TURN_SET) { //_targetRotation = transform.localRotation.eulerAngles.y + _currentCommand.Rate; } else if(_currentCommand.Command == AngieCommand.CommandType.FWD_1M) { Vector3 away = transform.position + transform.forward + (Vector3.up * 1000f); RaycastHit rchit; if( Physics.Raycast( away, Vector3.down, out rchit, Mathf.Infinity, 1 << LayerMask.NameToLayer("Terrain"))) _targetPosition = rchit.point; } else if(_currentCommand.Command == AngieCommand.CommandType.FWD_5M) { Vector3 away = transform.position + (transform.forward * 5f) + (Vector3.up * 1000f); RaycastHit rchit; if( Physics.Raycast( away, Vector3.down, out rchit, Mathf.Infinity, 1 << LayerMask.NameToLayer("Terrain"))) _targetPosition = rchit.point; } else if(_currentCommand.Command == AngieCommand.CommandType.BACK_1M) { Vector3 away = transform.position + (-transform.forward) + (Vector3.up * 1000f); RaycastHit rchit; if( Physics.Raycast( away, Vector3.down, out rchit, Mathf.Infinity, 1 << LayerMask.NameToLayer("Terrain"))) _targetPosition = rchit.point; } } // Always apply gravity ApplyGravity(); // Always apply movement _flags = _controller.Move( (transform.forward * yaxis) * (_movementSpeed * Time.deltaTime) + ((Vector3.up * _verticalSpeed) * Time.deltaTime) ); //Always reclamp for nice effect // TODO: ManualQueue(); }
public AngieCommand(AngieCommand.CommandType command, float rate = 0f) { _command = command; _rate = rate; }
public void EnqueueCommand(AngieCommand command) { Debug.Log ("Enqueing " + command.Command); _queue.Enqueue(command); }