public FixedPointWalking() { this.nextBehavior = this; float duration = 5f; timeUntilSwitchbehavior = Time.time + duration; }
private void AddMovementInherent() { var behavior = this.movementBehavior.GetBehaviorAndMovement(); this.movementBehavior = behavior.behavior; base.totalMovement = new Movement(behavior.movementAdded); }
RelativeTo(this IMovementBehavior character, Transform camera) { // get the velocity under camera's rotation projected onto the xz-plane var vel = Vector3.ProjectOnPlane(camera.rotation * character.Velocity, Vector3.up); return(Time.deltaTime * vel); }
private void Awake() { agent = gameObject.GetComponent <NavMeshAgent>(); player = GameObject.FindWithTag("Player"); /* Initializing interfaces */ movementBehavior = new RoamBehavior(agent, 5); AddDashAbility(); }
private void Awake() { agent = gameObject.GetComponent <NavMeshAgent>(); player = GameObject.FindWithTag("Player"); health = new Health(10); /* Initializing interfaces */ movementBehavior = new RoamBehavior(agent, 8); SetupAbilities(); }
void Start() { player = GetComponent <CharacterController>(); // set movement behaviors walkBehavior = new WalkBehavior(this, walkSpeed, walkAccelerationTime, runDeaccelerationTime, snailThreshold); runBehavior = new RunBehavior(this, runSpeed, runAccelerationTime, runDeaccelerationTime); glideBehavior = new GlideBehavior(this); // default movement behavior is walking movement = walkBehavior; }
public Unit(string name, UnitTypes unitType, Faction side, IMovementBehavior movementBehavior, IAttackBehavior attackBehavior, ITargetBehavior targetBehavior) { _name = name; _experience = 50; _resources = 50; _side = side; _unitType = unitType; _movementBehavior = movementBehavior; _movementBehavior.Owner = this; _attackBehavior = attackBehavior; _attackBehavior.Owner = this; _targetBehavior = targetBehavior; _targetBehavior.Owner = this; _unitView = new UnitView(this, unitType); }
void Update() { var input = new Vector3(Input.GetAxisRaw("Horizontal"), 0f, Input.GetAxisRaw("Vertical")); if (Input.GetButton("Run")) { movement = runBehavior; } else { movement = walkBehavior; } movement.Update(input); // rotate the player to look in the direction of the input transform.LookAt( transform.position + Vector3.ProjectOnPlane(viewCamera.rotation * input, Vector3.up) ); player.Move(movement.RelativeTo(viewCamera)); }