private bool IsAimmingTo(Vector3 point) { float dif = AimmingControl.CalcRotationTo( _unit.launcher.transform.position, point, _unit.launcher.transform.rotation.eulerAngles.y); return(dif < 1); }
private bool Move() { speed += ACCELERATE * TimeHelper.deltaTime; speed = Mathf.Min(speed, SPEED_MAX); float rotSpeed = speed / SPEED_MAX * SPEED_ROTATE; Vector3 destination = GetCurrentDestination(); AimmingControl.RESULT rotateR = AimmingControl.Rotate( transform.position, destination, transform.rotation.eulerAngles.y, rotSpeed, 0.01f); transform.Rotate(new Vector3(0, rotateR.turnDegree, 0)); Vector3 line = destination - transform.position; float dist = line.magnitude; Vector3 orientation = UnitHelper.GetOrientation(transform); VectorHelper.ResizeVector(ref orientation, dist); Vector3 p = orientation + transform.position; float radius = _shoot.target.unit.dataUnit.GetHurtRadius(); MovingControl.RESULT moveR = MovingControl.MoveTo(transform.position, p, speed, radius + heightInitOffset); transform.position = moveR.destination; return(moveR.arrived); }
// private TankSpineAttach _spineAttach; public UnitDriver(GameObject owner, GameObject body, float speed) { _unit = owner.GetComponent <Unit> (); _game = BattleGame.instance; _shortPath = new ShortPath(_unit, _game.mapGrid); this._owner = owner; this._body = body; _engine = new TankEngine(_unit); _turningControl = new AimmingControl(body, ROTATION_SPEED); this._speed = speed; // _spineAttach = owner.GetComponent<TankSpineAttach> (); }
private void UpdateStateMachine() { int result = _stateMachine.Tick(); IState state = _stateMachine.currentState; if (state is UnitStateIdle) { } else if (state is UnitStateDead) { } else if (state is UnitStateFighting) { } else if (state is UnitStateEntering) { if (result == (int)UnitStateEntering.RESULT.DONE) { } } else if (state is UnitStateFire) { if (result == (int)UnitStateFire.RESULT.DONE) { _stateMachine.Change(new UnitStateFighting(this)); } } if (unit.dataUnit.bodyType == DataConfig.BODY_TYPE.CAR_WITH_CANNON) { if (_unitDriver.engine.IsStopped()) { float speed = AIMMING_ROTATE_SPEED; AimmingControl.RESULT r = AimmingControl.Rotate( body.transform.rotation.eulerAngles.y, launcher.transform.rotation.eulerAngles.y, speed, 0.01f); body.transform.Rotate(new Vector3(0, r.turnDegree, 0)); } else { launcher.transform.rotation = body.transform.rotation; } } }
// Use this for initialization void Start() { _game = BattleGame.instance; _aimmingControl = new AimmingControl(launcher, AIMMING_ROTATE_SPEED); _gridCorrect = new UnitGridCorrect(this, _game.mapGrid); _targetSelect = new UnitTargetSelect(this, _game.unitGroup); _unitFire = new UnitFire(this); _unitDriver = new UnitDriver(gameObject, body, unit.dataUnit.speed); _collisionDetector = new UnitCollisionDetector(this, _game.unitGroup); _stateMachine.Change(new UnitStateIdle(this)); CreateHPBar(); _unitTrack = new UnitTrack(this); }