/// <summary> /// Sets the state of the Player /// </summary> /// <param name="state">Which state to set</param> /// <exception cref="ArgumentOutOfRangeException"></exception> public void SetState(PlayerStates state) { PlayerBaseState playerState; switch (state) { case PlayerStates.Shoot: playerState = new ShootingState(this); break; case PlayerStates.Walking: playerState = new WalkingState(this); break; case PlayerStates.Talking: playerState = new TalkingState(this); break; case PlayerStates.Win: playerState = new WinState(this); break; default: throw new ArgumentOutOfRangeException(nameof(state), state, null); } _currentState?.ExitState(); _currentState = playerState; _currentState.EnterState(); }
public void WalkingStateTransition() { var state = new WalkingState(peach); peach.ActionState = state; peach.Sprite = PeachSpriteFactory.Instance.FactoryMethod(peach); }
public void Stop() { if (!isWalking) { CurrentWalkingState = WalkingState.Still; } }
public void setDestination(GameObject dest) { // Finds all the movements to the final destination movements = (GameObject.Find ("Paths").GetComponent<Navigation>()).findPath(transform.position, dest.transform.position); pathIndex = 1; currentState = WalkingState.OnPath; }
public Spiny(Level l, Point position, Sprite eggSprite, Sprite walkingSprite) : base(l, position, eggSprite, NullSprite.Instance) { //Spinies are thrown. WalkingState walkingState = new WalkingState(this, walkingSprite, Velocity); Velocity = new Vector2(0, -5.0f); (new EggState(this, walkingState)).Enter(); }
public override void MoveUnit(int unitIndex, Vector3 location) { Vector3 startingPosition = _units[unitIndex].GetCurrentTile().LocalLocation; List <GridTile> path = _gridController.FindPath(startingPosition, location); UnitState nextState = new IdleState(_units[unitIndex]); WalkingState state = new WalkingState(_units[unitIndex], nextState, path, OnUnitPathFail); _units[unitIndex].ChangeState(state); }
public override void OnUnitPathFail(GridTile current, GridTile nextTile, UnitState nextState) { Vector3 startingPosition = current.LocalLocation; List <GridTile> path = _gridController.FindPath(startingPosition, nextTile.LocalLocation); WalkingState moveState = new WalkingState(nextState.Parent, nextState, path, OnUnitPathFail); nextState.Parent.ChangeState(moveState); }
void Awake() { walkingState = new WalkingState(this); runningState = new RunningState(this); sleepingState = new SleepingState(this); anim = GetComponent <Animator>(); energy = GetComponent <Energy>(); selection = GetComponent <Selection>(); Debug.Log("my STARTING energy level is : " + energy.EnergyLevel); }
private void InitaliseFSM() { _fsm = new FSM.FSM(); State dormantState = new DormantState(this); State idleState = new IdleState(this); State walkingState = new WalkingState(this); State pushingState = new PushingState(this); State liftingState = new LiftingState(this); _fsm.AddTransition(dormantState, idleState, () => { return(!_dormant); }); _fsm.AddTransition(idleState, dormantState, () => { return(_dormant); }); _fsm.AddTransition(idleState, walkingState, () => { return(_heading != Vector3.zero); }); _fsm.AddTransition(walkingState, idleState, () => { Vector3 vel = _rb.velocity; vel.y = 0f; return(_heading == Vector3.zero && vel == Vector3.zero); }); // Pushing _fsm.AddTransition(idleState, pushingState, () => { if (Input.GetKeyDown(KeyCode.E)) { return(BeginPushing()); } return(false); }); _fsm.AddTransition(pushingState, idleState, () => { return(Input.GetKeyDown(KeyCode.E)); }); // Lifting _fsm.AddTransition(idleState, liftingState, () => { if (Input.GetKeyDown(KeyCode.Q)) { return(BeginLifting()); } return(false); }); _fsm.AddTransition(liftingState, idleState, () => { return(Input.GetKeyDown(KeyCode.Q)); }); _fsm.SetDefaultState(idleState); }
public void ChangeWalkState(WalkingState walkingState) { if (walkingState == WalkingState.Stand) { _isWalking = false; } else if (walkingState == WalkingState.Walk) { _isWalking = true; } }
void Update() { //Check the keyboard state and set the character state accordingly if (Input.GetKey(KeyCode.LeftArrow)) { state = WalkingState.WalkLeft; } else if (Input.GetKey(KeyCode.RightArrow)) { state = WalkingState.WalkRight; } else { state = WalkingState.Standing; } Vector3 moveDirection = new Vector3(); switch (state) { case(WalkingState.Standing): //Reset the horizontal flip for clarity ragePixel.SetHorizontalFlip(false); ragePixel.PlayNamedAnimation("STAY", false); if (arrowLeft != null) arrowLeft.SetTintColor(Color.gray); if (arrowRight != null) arrowRight.SetTintColor(Color.gray); break; case (WalkingState.WalkLeft): //Flip horizontally. Our animation is drawn to walk right. ragePixel.SetHorizontalFlip(true); //PlayAnimation with forceRestart=false. If the WALK animation is already running, doesn't do anything. Otherwise restarts. ragePixel.PlayNamedAnimation("WALK", false); //Move direction. X grows right so left is -1. moveDirection = new Vector3(-1f, 0f, 0f); if (arrowLeft != null) arrowLeft.SetTintColor(Color.white); if (arrowRight != null) arrowRight.SetTintColor(Color.gray); break; case (WalkingState.WalkRight): //Not flipping horizontally. Our animation is drawn to walk right. ragePixel.SetHorizontalFlip(false); //PlayAnimation with forceRestart=false. If the WALK animation is already running, doesn't do anything. Otherwise restarts. ragePixel.PlayNamedAnimation("WALK", false); //Move direction. X grows right so left is +1. moveDirection = new Vector3(1f, 0f, 0f); if (arrowLeft != null) arrowLeft.SetTintColor(Color.gray); if (arrowRight != null) arrowRight.SetTintColor(Color.white); break; } //Move the sprite into moveDirection at walkingSpeed pixels/sec transform.Translate(moveDirection * Time.deltaTime * walkingSpeed); }
public BotLogics(PacketHandler ph, PlayerObject[] players, List <Client> clients) { this.ph = ph; this.players = players; local = ph.getLocalPlayer(); this.otherClients = clients; shootTimer = new Timer(100); shootTimer.Elapsed += new ElapsedEventHandler(_shootTimerElapsed); shootTimer.Enabled = true; dropped_items = new List <Item>(); walkingState = WalkingState.EnemySearch; }
public BotLogics(PacketHandler ph, PlayerObject[] players, List<Client> clients) { this.ph = ph; this.players = players; local = ph.getLocalPlayer(); this.otherClients = clients; shootTimer = new Timer(100); shootTimer.Elapsed += new ElapsedEventHandler(_shootTimerElapsed); shootTimer.Enabled = true; dropped_items = new List<Item>(); walkingState = WalkingState.EnemySearch; }
void FixedUpdate() { if (!Enabled) { return; } if (transform.position == lastPosition) { isMouving = false; } else { isMouving = true; lastPosition = transform.position; } var vel = GetComponent <Rigidbody>().velocity; if (LookAt && GetComponent <Rigidbody>().velocity != Vector3.zero && !vel.Equals(Vector3.zero)) { transform.rotation = Quaternion.LookRotation(vel); } Steering = Vector3.zero; //ObstacleAvoidanceSteeringType.Process(); WallAvoidanceSteeringType.Process(); FollowLeaderSteeringType.Process(); FlockingSteeringType.Process(); ArriveSteeringType.Process(); SeekSteeringType.Process(); FleeSteeringType.Process(); ApplySteering(); magVelocety = this.GetComponent <Rigidbody>().velocity.magnitude; if (magVelocety < 0.3f || !isMouving) { WalkingState = WalkingState.Idle; } else if (magVelocety > 0.3f && magVelocety < 3.8f) { WalkingState = WalkingState.Walking; } else if (magVelocety > 3.8f) { WalkingState = WalkingState.Runnning; } }
protected void Move(Vector2 target) { this.target = target; if (!IsTargetInRange()) { animator.SetFloat(Consts.MoveSpeed, moveSpeed); state = WalkingState.Walking; } else { StopMovement(); TargetReachedCallback?.Invoke(); } }
// update the toNode, according to neighbor node, current walking direction, last input void UpdateToNode() { // do not update anything when walking towards target node if (walkingState == WalkingState.walking) { return; } int x = -fromNode.y, y = fromNode.x; bool left = isWalkable(levelMap[x, y - 1]), right = isWalkable(levelMap[x, y + 1]), up = isWalkable(levelMap[x - 1, y]), down = isWalkable(levelMap[x + 1, y]); if ((lastInput == Vector2.left && left) || lastInput == Vector2.right && right || lastInput == Vector2.up && up || lastInput == Vector2.down && down ) { currentWalkingDirection = lastInput; toNode = new Vector2Int(fromNode.x + lastInput.x, fromNode.y + lastInput.y); changePackmanFace(lastInput); } else if ((currentWalkingDirection == Vector2.left && left) || currentWalkingDirection == Vector2.right && right || currentWalkingDirection == Vector2.up && up || currentWalkingDirection == Vector2.down && down ) { toNode = new Vector2Int(fromNode.x + currentWalkingDirection.x, fromNode.y + currentWalkingDirection.y); } else { walkingState = WalkingState.stopped; } /** * Debug.Log("======= UpdateToNode====="); * * Debug.Log("FromNode: " + fromNode.x + "," + fromNode.y); * Debug.Log("toNode: " + toNode.x + "," + toNode.y); * Debug.Log("left:" + levelMap[x, y - 1] + left + ", right:" + levelMap[x, y + 1] + right + ", up:" + levelMap[x - 1, y] + up + ", down:" + levelMap[x + 1, y] + down); * Debug.Log("walkingState:" + walkingState); * Debug.Log("lastInput:" + lastInput); * Debug.Log("currentWalkingDirection:" + currentWalkingDirection); */ }
public WalkingPlayer(SpellswordGame game, World gameWorld) { this.game = game; this.gameWorld = gameWorld; this.thisEntity = new Player("BackwardsStill", "Spellsword"); animator = new Animator(game, this); controller = new PlayerController(game); this.CurrentTileLocation = new Point(8, 21); this.Location = gameWorld.GetTileLocation(CurrentTileLocation); CurrentSprite = game.Content.Load <Texture2D>(((Player)thisEntity).WorldImage); CurrentWalkingState = WalkingState.Still; MovementQueue = new Stack <Vector2>(); }
private void Awake() { var standingState = new StandingState(); var walkingState = new WalkingState(); var runningState = new RunningState(); standingState.Constructor(this); walkingState.Constructor(this); runningState.Constructor(this); _movementStateMachine.RegisterState(MovementState.Standing, standingState); _movementStateMachine.RegisterState(MovementState.Walking, walkingState); _movementStateMachine.RegisterState(MovementState.Running, runningState); _movementStateMachine.EnterState(MovementState.Standing); PlayerMovement.Constructor(_movementStateMachine); }
public void OnWeaponPickup(int wpnid, short ammo, short ammoin) { if (walkingState == WalkingState.WeaponSearch) // only if lookign for weapon, pick it up { if (isPrimaryWeapon(wpnid)) { ph.send_weaponchange_9(wpnid); local.Currentweapon = (byte)wpnid; local.Ammo = ammo; local.AmmoIn = ammoin; // need remove item from dropped item list walkingState = WalkingState.EnemySearch; } } }
public void OnWeaponBuy(byte wpn_id) { switch (wpn_id) { case 248: return; case 249: return; case 250: return; case 251: return; case 252: //ph.LogConsole("Cannot buy ( wrong team)"); return; case 253: //ph.LogConsole("Not enough money to buy weapon!"); return; case 254: //ph.LogConsole("Cannot buy this weapon! Buytime expired "); return; case 255: //ph.LogConsole("Not in the right area to buy weapon!"); return; default: break; } if (isPrimaryWeapon(wpn_id)) { walkingState = WalkingState.EnemySearch; } local.Currentweapon = wpn_id; local.Ammo = (short)Weapons.wpns[wpn_id].ammo; local.AmmoIn = (short)Weapons.wpns[wpn_id].ammoIn; }
protected void Move(Vector2 target) { this.target = target; if (!IsTargetInRange()) { var current = new Vector2(transform.position.x, transform.position.y); rb.velocity = (new Vector2(target.x, target.y) - current).normalized * moveSpeed; animator.SetFloat(Consts.MoveSpeed, moveSpeed); state = WalkingState.Walking; } else { StopMovement(); TargetReachedCallback?.Invoke(); } }
private void Move() { // for test only // 1. calculate next walking offset Vector2 lerp = new Vector2((float)(toNode.x - fromNode.x) / 20, (float)(toNode.y - fromNode.y) / 20f); pacStudent.transform.localPosition = new Vector2(pacStudent.transform.localPosition.x + lerp.x, pacStudent.transform.localPosition.y + lerp.y); // 2. if next walking offset is equal to toNode, change walking state to stop. if (Math.Abs(pacStudent.transform.localPosition.x - (float)toNode.x) < 0.1 && Math.Abs(pacStudent.transform.localPosition.y - (float)toNode.y) < 0.1) { pacStudent.transform.localPosition = new Vector2(toNode.x, toNode.y); walkingState = WalkingState.stopped; fromNode = toNode; EatNode(fromNode.x, fromNode.y); } }
private Vector2 walkingStateToVector(WalkingState state) { switch (state) { case WalkingState.Down: return(new Vector2(0, -1)); case WalkingState.Up: return(new Vector2(0, 1)); case WalkingState.Left: return(new Vector2(-1, 0)); case WalkingState.Right: return(new Vector2(1, 0)); } return(Vector2.zero); }
// Update is called once per frame void Update() { WalkingState currentState = getMyWalkingState(); Vector2 v = walkingStateToVector(currentState); if (currentState == WalkingState.None) { // don't want to walk too often.. if (DateTime.Now < _nextMovement) { anim.SetBool("iswalking", false); return; } v = getRandomVector2(); currentState = getWalkingState(v); changeMyWalkingState(currentState); } if (v != Vector2.zero) { anim.SetBool("iswalking", true); anim.SetFloat("input_x", v.x); anim.SetFloat("input_y", v.y); } else { anim.SetBool("iswalking", false); } rigidBody.MovePosition(rigidBody.position + v * Time.deltaTime * MovementSpeed); _framesToWalk--; if (_framesToWalk < 1) { System.Random rnd = new System.Random(DateTime.Now.Millisecond); int msToAdd = rnd.Next(2000, 5000); Debug.LogFormat("Waiting {0} milliseconds", msToAdd); _nextMovement = DateTime.Now.AddMilliseconds(msToAdd); } }
public void MoveUp() { if (!isWalking) { isWalking = true; this.CurrentWalkingState = WalkingState.Up; Point desiredTileLocation = new Point(CurrentTileLocation.X, CurrentTileLocation.Y - 1); if (gameWorld.IsOnMap(desiredTileLocation) && !gameWorld.IsOccupied(desiredTileLocation)) { QueueMovement(new Vector2(0, -1 * Parameters.pixelsMovedPerFrame)); QueueMovement(new Vector2(0, -1 * Parameters.pixelsMovedPerFrame)); //this.CurrentTileLocation.Y -= 1; this.CurrentTileLocation = new Point(CurrentTileLocation.X, CurrentTileLocation.Y - 1); } else { QueueMovement(new Vector2(0, 0)); QueueMovement(new Vector2(0, 0)); } } }
public void SpeedController() { if ((Input.GetAxis("Horizontal") != 0 || Input.GetAxis("Vertical") != 0) && VelocityMagnitude > 0 && CharCont.isGrounded) { if (Input.GetButton("Run")) { walkingstate = WalkingState.Running; CharMotor.movement.maxForwardSpeed = RunSpeed; CharMotor.movement.maxSidewaysSpeed = RunSpeed; CharMotor.movement.maxBackwardsSpeed = RunSpeed / 2; } else if (Input.GetButtonDown("Jump")) { walkingstate = WalkingState.Jumping; anim.SetBool("Jump", Input.GetButtonDown("Jump")); } else { walkingstate = WalkingState.Walking; CharMotor.movement.maxForwardSpeed = WalkSpeed; CharMotor.movement.maxSidewaysSpeed = WalkSpeed; CharMotor.movement.maxBackwardsSpeed = WalkSpeed / 2; } } else if (Input.GetButtonDown("Jump") && CharCont.isGrounded) { walkingstate = WalkingState.Jumping; anim.SetBool("Jump", Input.GetButtonDown("Jump")); } else { walkingstate = WalkingState.Idle; } }
public void Awake() { Input = GetComponent <IPlayerInput>(); Anim = GetComponent <IPlayerAnimationManager>(); RollHitbox = GetComponent <PlayerRollAttackHitbox>(); DiveHitbox = GetComponent <PlayerDiveAttackHitbox>(); Motor = GetComponent <PlayerMotor>(); Walking = new WalkingState(this); StandardJumping = new StandardJumpingState(this); DoubleJumping = new DoubleJumpingState(this); RollJumping = new RollJumpingState(this); SideFlipJumping = new SideFlipJumpingState(this); FreeFall = new FreeFallState(this); WallSliding = new WallSlidingState(this); WallJumping = new WallJumpingState(this); Rolling = new RollingState(this); Diving = new DivingState(this); Bonking = new BonkingState(this); GrabbingLedge = new GrabbingLedgeState(this); _allStates = new[] { Walking, FreeFall, WallSliding, WallJumping, Rolling, Diving, Bonking, GrabbingLedge }; // Start in FreeFall ChangeState(FreeFall); Debug.Log("Jump speed: " + PlayerConstants.STANDARD_JUMP_VSPEED); }
public void MoveUnit(AIUnitController unit, Vector3 location, int checkCount = 0) { Vector3 startingPosition = unit.GetCurrentTile().LocalLocation; List <GridTile> path = _gridController.FindPath(startingPosition, location); int count = checkCount + 1; int totalLocations = unit.GetLocationCount(); if (path.Count > 0) { UnitState nextState = new CallbackUnitState <AIUnitController>(unit, OnUnitPathFinished, unit as AIUnitController); WalkingState state = new WalkingState(unit, nextState, path, OnUnitPathFail); unit.ChangeState(state); return; } else if (count < totalLocations) { unit.SetNextLocation(); MoveUnit(unit, unit.GetCurrentLocation(), count); } }
public WalkingState walk(float walkingSpeed) { //code to walk if(pathIndex < movements.Count-1) { NPCFidget fidgets = GetComponent<NPCFidget>(); fidgets.StartWalking(); transform.LookAt (movements[pathIndex]); transform.Translate(Vector3.forward * Time.deltaTime * walkingSpeed); transform.position = new Vector3(transform.position.x, Terrain.activeTerrain.SampleHeight(transform.position), transform.position.z); if (Vector3.Distance(transform.position, movements[pathIndex]) < Random.Range(1,4)) { pathIndex++; } return currentState; } //Maybe here we can choose a random direction to face and a random small amount to move forward and make them move that much currentState = WalkingState.NotStarted; return WalkingState.ReachedDestination; }
private WalkingState getWalkingState(Vector2 state) { WalkingState s = WalkingState.None; if (state == new Vector2(-1, 0)) { s = WalkingState.Left; } else if (state == new Vector2(1, 0)) { s = WalkingState.Right; } else if (state == new Vector2(0, -1)) { s = WalkingState.Down; } else if (state == new Vector2(0, 1)) { s = WalkingState.Up; } return(s); }
public WalkingState walk(float walkingSpeed) //code to walk { if (pathIndex < movements.Count - 1) { NPCFidget fidgets = GetComponent <NPCFidget>(); fidgets.StartWalking(); transform.LookAt(movements[pathIndex]); transform.Translate(Vector3.forward * Time.deltaTime * walkingSpeed); transform.position = new Vector3(transform.position.x, Terrain.activeTerrain.SampleHeight(transform.position), transform.position.z); if (Vector3.Distance(transform.position, movements[pathIndex]) < Random.Range(1, 4)) { pathIndex++; } return(currentState); } //Maybe here we can choose a random direction to face and a random small amount to move forward and make them move that much currentState = WalkingState.NotStarted; return(WalkingState.ReachedDestination); }
// yo dawg private void flipMyState() { WalkingState myState = getMyWalkingState(); if (myState == WalkingState.None) { return; } WalkingState newState = WalkingState.None; switch (myState) { case WalkingState.Down: newState = WalkingState.Up; break; case WalkingState.Up: newState = WalkingState.Down; break; case WalkingState.Left: newState = WalkingState.Right; break; case WalkingState.Right: newState = WalkingState.Left; break; } if (newState != WalkingState.None) { Debug.Log("Flipping to " + newState.ToString()); changeMyWalkingState(newState); } }
public void SpeedController() { if ((Input.GetAxis("Horizontal") != 0 || Input.GetAxis("Vertical") != 0) && VelocityMagnitude > 0) { if (Input.GetButton("Run")) { walkingstate = WalkingState.Running; CharMotor.movement.maxForwardSpeed = RunSpeed; CharMotor.movement.maxSidewaysSpeed = RunSpeed; CharMotor.movement.maxBackwardsSpeed = RunSpeed / 2; } else { walkingstate = WalkingState.Walking; CharMotor.movement.maxForwardSpeed = WalkSpeed; CharMotor.movement.maxSidewaysSpeed = WalkSpeed; CharMotor.movement.maxBackwardsSpeed = WalkSpeed / 2; } } else { walkingstate = WalkingState.Idle; } }
public void SpeedController() { if ((Input.GetAxis("Horizontal") != 0 || Input.GetAxis("Vertical") != 0) && VelocityMagnitude > 0) { if (Input.GetButton("Run")) { walkingstate = WalkingState.Running; CharMotor.movement.maxForwardSpeed = RunSpeed; CharMotor.movement.maxSidewaysSpeed = RunSpeed; CharMotor.movement.maxBackwardsSpeed = RunSpeed / 2; } else { walkingstate = WalkingState.Walking; CharMotor.movement.maxForwardSpeed = WalkSpeed; CharMotor.movement.maxSidewaysSpeed = WalkSpeed; CharMotor.movement.maxBackwardsSpeed = WalkSpeed / 2; } } else { walkingstate = WalkingState.Idle; } }
public void OnWeaponPickup(int wpnid, short ammo, short ammoin) { if (walkingState == WalkingState.WeaponSearch) // only if lookign for weapon, pick it up { if (isPrimaryWeapon(wpnid)) { ph.send_weaponchange_9(wpnid); local.Currentweapon = (byte)wpnid; local.Ammo = ammo; local.AmmoIn = ammoin; // need remove item from dropped item list walkingState = WalkingState.EnemySearch; } } }
public void SpeedController() { if ((Input.GetAxis("Horizontal") != 0 || Input.GetAxis("Vertical") != 0) && VelocityMagnitude > 0 && CharCont.isGrounded ) { if (Input.GetButton("Run")) { walkingstate = WalkingState.Running; CharMotor.movement.maxForwardSpeed = RunSpeed; CharMotor.movement.maxSidewaysSpeed = RunSpeed; CharMotor.movement.maxBackwardsSpeed = RunSpeed / 2; } else if (Input.GetButtonDown("Jump")) { walkingstate = WalkingState.Jumping; anim.SetBool ("Jump", Input.GetButtonDown("Jump")); } else { walkingstate = WalkingState.Walking; CharMotor.movement.maxForwardSpeed = WalkSpeed; CharMotor.movement.maxSidewaysSpeed = WalkSpeed; CharMotor.movement.maxBackwardsSpeed = WalkSpeed / 2; } } else if (Input.GetButtonDown("Jump") && CharCont.isGrounded ) { walkingstate = WalkingState.Jumping; anim.SetBool ("Jump",Input.GetButtonDown("Jump")); } else { walkingstate = WalkingState.Idle; } }
public void OnRoundStart() { int money = local.Money; ph.send_buy_23(30); ph.send_buy_23(32); ph.send_buy_23(61); ph.send_buy_23(58); ph.send_buy_23(57); ph.send_buy_23(62); if (isPrimaryWeapon(local.Currentweapon))// has primary weapon { walkingState = WalkingState.EnemySearch; } else if (ItemScan("primary") != null) { walkingState = WalkingState.WeaponSearch; } else { walkingState = WalkingState.EnemySearch; } b_isRoundStarted = true; currentRoute = null; }
public void StopMovement() { rb.velocity = Vector2.zero; animator.SetFloat(Consts.MoveSpeed, 0f); state = WalkingState.Standing; }
// Update is called once per frame void Update() { // the goal is to go towards the player goal = player.transform; // stop the enemies if there is no path to the player if (this.GetComponent<NavMeshAgent> ().isActiveAndEnabled) { if (startNav) { agent.SetDestination(goal.position); } if (agent.pathStatus == NavMeshPathStatus.PathPartial && !agent.isOnOffMeshLink) { agent.Stop (); //transform.LookAt(goal); } else if (agent.pathStatus == NavMeshPathStatus.PathInvalid && !agent.isOnOffMeshLink) { agent.Stop (); } else { agent.Resume(); } } // if the enemies is not on the UFO if (!agent.isOnOffMeshLink) { if (Mathf.Abs(agent.velocity.x) > 0.01f || Mathf.Abs(agent.velocity.z) > 0.001f) { walkState = WalkingState.Running; //set animation speed based on navAgent 'Speed' variable animController.speed = agent.speed; } else { walkState = WalkingState.Idle; } // if the enemies is on the UFO } else { agent.ActivateCurrentOffMeshLink(true); float stepUp = 1.0f * agent.speed * Time.deltaTime; float stepDown = 2.0f * agent.speed * Time.deltaTime; Vector3 endPos = agent.currentOffMeshLinkData.endPos + Vector3.up*agent.baseOffset; Vector3 middlePos = agent.currentOffMeshLinkData.startPos + Vector3.up*0.6f; middlePos.Set(agent.currentOffMeshLinkData.startPos.x + 0.8f*(endPos.x-agent.currentOffMeshLinkData.startPos.x), middlePos.y, agent.currentOffMeshLinkData.startPos.z + 0.8f*(endPos.z-agent.currentOffMeshLinkData.startPos.z)); // transform.LookAt(goal); walkState = WalkingState.jumpingDown; if (transform.position != middlePos && jumpDown == false) { transform.position = Vector3.MoveTowards(transform.position, middlePos, stepUp); } else if (transform.position.y >= (middlePos.y-0.8) && jumpDown == false) { jumpDown = true; } if (transform.position != endPos && jumpDown == true) { transform.position = Vector3.MoveTowards(transform.position, endPos, stepDown); } else if (transform.position.y <= (endPos.y + 0.5) && jumpDown == true) { jumpDown = false; agent.CompleteOffMeshLink(); Debug.Log ("Monster jumping down"); } } // check the distance from the enemy to player and decide whether to attack or punch Vector3 distanceToPlayer = transform.position - goal.position; if (distanceToPlayer.magnitude <= 2.5f) { animController.SetInteger ("attackState", (int)AttackState.Attack); } else { animController.SetInteger("attackState", (int)AttackState.NoAttack); } if (distanceToPlayer.magnitude <= 1.6f) { //transform.LookAt(goal); Invoke("punchPlayer", 0.15f); } // send move state information to animator controller animController.SetInteger ("walkingState", (int)walkState); }
void ShootController() { if (Arma != -1) { if (Input.GetButton("Fire1") && CurrentWeapon.Balas > 0 && Recargando == false) { if (shootTime <= Time.time) { walkingState = WalkingState.Shooting; shootTime = Time.time + CurrentWeapon.fireRate; currentRecoil1 += new Vector3(CurrentWeapon.recoilRotation.x, Random.Range(-CurrentWeapon.recoilRotation.y, CurrentWeapon.recoilRotation.y)); currentRecoil3 += new Vector3(Random.Range(-CurrentWeapon.recoilKickBack.x, CurrentWeapon.recoilKickBack.x), Random.Range(-CurrentWeapon.recoilKickBack.y, CurrentWeapon.recoilKickBack.y), CurrentWeapon.recoilKickBack.z); Audio.clip = CurrentWeapon.disparoFX; Audio.Play(); CurrentWeapon.weaponTransform.GetComponent<Animation>().Play(CurrentWeapon.ShotAnimGun); CurrentWeapon.Balas -= 1; canReload = false; RaycastHit Hit; if (Physics.Raycast(CurrentWeapon.spawnPoint.position, CurrentWeapon.spawnPoint.TransformDirection(Vector3.forward), out Hit, 250)) { Hit.transform.SendMessageUpwards("GetBulletDamage", CurrentWeapon.Name, SendMessageOptions.DontRequireReceiver); if (Hit.transform && Hit.collider.tag != "Enemy" && Hit.collider.tag != "ArmaTrigger" && Hit.collider.tag != "AscensorInt" && Hit.collider.tag != "NoBullet") { Instantiate(BulletHole, Hit.point, Quaternion.FromToRotation(Vector3.up, Hit.normal)); } if (Hit.collider.tag == "Enemy") { Hit.transform.gameObject.GetComponent<EnemyDead>().Health -= CurrentWeapon.Damage; GameObject Bullet; Bullet = (GameObject) Instantiate(BulletHole, Hit.point, Quaternion.FromToRotation(Vector3.up, Hit.normal)); Bullet.transform.parent = Hit.transform; Hit.transform.gameObject.GetComponent<AudioSource>().clip = Metal; Hit.transform.gameObject.GetComponent<AudioSource>().Play(); } if (Hit.collider.tag == "AscensorInt") { Hit.transform.gameObject.GetComponent<Ascensor>().Activado = true; } } } } else if (Input.GetButtonUp("Fire1") && Recargando == false) { canReload = true; } } if (Input.GetButton("Reload") && canReload == true && Recargando == false && CurrentWeapon.TotalB > 0) { canReload = false; Recargando = true; Audio.clip = CurrentWeapon.recargaFX; Audio.Play(); CurrentWeapon.Manos.GetComponent<Animation>().Play(CurrentWeapon.ReloadAnimHand); CurrentWeapon.weaponTransform.GetComponent<Animation>().Play(CurrentWeapon.ReloadAnimGun); StartCoroutine(Recarga()); } }
void SpeedController() { if ((Input.GetAxis("Horizontal") != 0 || Input.GetAxis("Vertical") != 0) && VelocityMagn > 0 && isAiming == false) { if (Input.GetButton("Run")) { walkingState = WalkingState.Running; } else { walkingState = WalkingState.Walking; } } else { walkingState = WalkingState.Idle; } }
void Update() { if(!isInSafeZone){ reduceHealth(1); } //Update Right Stick if(!castDirectionSet){ r_Xaxis = Input.GetAxis("R_XAxis_" + controllerNumber); r_Yaxis = -Input.GetAxis("R_YAxis_" + controllerNumber); } if(Input.GetButtonDown("RB_" + controllerNumber)||(Input.GetKey(KeyCode.Space) && controllerNumber==1)) { casting = true; } if(!casting) { //Check the keyboard state and set the character state accordingly if (Input.GetAxis("L_XAxis_"+controllerNumber) < 0) { state = WalkingState.WalkLeft; } else if (Input.GetAxis("L_XAxis_"+controllerNumber) > 0) { state = WalkingState.WalkRight; } else { state = WalkingState.Standing; } if(Input.GetAxis("L_YAxis_"+controllerNumber) < 0) { if(state == WalkingState.WalkLeft) { state= WalkingState.WalkUpLeft; } else if(state == WalkingState.WalkRight) { state = WalkingState.WalkUpRight; } else { state = WalkingState.WalkUp; } } else if(Input.GetAxis("L_YAxis_"+controllerNumber) > 0) { if(state == WalkingState.WalkLeft) { state= WalkingState.WalkDownLeft; } else if(state == WalkingState.WalkRight) { state=WalkingState.WalkDownRight; } else { state = WalkingState.WalkDown; } } if(state == WalkingState.Standing) { getStandAnimation(lastState); ragePixel.PlayNamedAnimation(animation, false); } else switch (state) { case (WalkingState.WalkLeft): //Flip horizontally. Our animation is drawn to walk right. ragePixel.SetHorizontalFlip(true); //PlayAnimation with forceRestart=false. If the WALK animation is already running, doesn't do anything. Otherwise restarts. ragePixel.PlayNamedAnimation("WALK R", false); //Move direction. X grows right so left is -1. moveDirection = new Vector3(-1f, 0f, 0f); lastState=LastState.L; break; case (WalkingState.WalkRight): //Not flipping horizontally. Our animation is drawn to walk right. //ragePixel.SetHorizontalFlip(false); //PlayAnimation with forceRestart=false. If the WALK animation is already running, doesn't do anything. Otherwise restarts. ragePixel.SetHorizontalFlip(false); ragePixel.PlayNamedAnimation("WALK R", false); //Move direction. X grows right so left is +1. moveDirection = new Vector3(1f, 0f, 0f); lastState=LastState.R; break; case (WalkingState.WalkUp): ragePixel.SetHorizontalFlip(false); moveDirection = new Vector3(0f,1f,0f); ragePixel.PlayNamedAnimation("WALK U", false); lastState=LastState.U; break; case (WalkingState.WalkDown): ragePixel.SetHorizontalFlip(false); moveDirection = new Vector3(0f,-1f,0f); ragePixel.PlayNamedAnimation("WALK D", false); lastState=LastState.D; break; case (WalkingState.WalkUpLeft): ragePixel.SetHorizontalFlip(true); moveDirection = new Vector3(-1f,1f,0f)/Mathf.Pow(2f,0.5f); ragePixel.PlayNamedAnimation("WALK UR", false); lastState=LastState.UL; break; case (WalkingState.WalkUpRight): ragePixel.SetHorizontalFlip(false); moveDirection = new Vector3(1f,1f,0f)/Mathf.Pow(2f,0.5f); ragePixel.PlayNamedAnimation("WALK UR", false); lastState=LastState.UR; break; case (WalkingState.WalkDownLeft): ragePixel.SetHorizontalFlip(true); moveDirection = new Vector3(-1f,-1f,0f)/Mathf.Pow(2f,0.5f); ragePixel.PlayNamedAnimation("WALK DR", false); lastState=LastState.DL; break; case (WalkingState.WalkDownRight): ragePixel.SetHorizontalFlip(false); moveDirection = new Vector3(1f,-1f,0f)/Mathf.Pow(2f,0.5f); ragePixel.PlayNamedAnimation("WALK DR", false); lastState=LastState.DR; break; } }else if(!castDirectionSet) { if((Input.GetAxis("R_XAxis_" + controllerNumber)==0&&Input.GetAxis("R_YAxis_" + controllerNumber)==0)) { //getStandAnimation(lastState); if(lastState == LastState.R||lastState==LastState.DR||lastState==LastState.UR) { r_Xaxis = 1f; } else if(lastState == LastState.L||lastState==LastState.DL||lastState==LastState.UL) { r_Xaxis = -1f; } if(lastState == LastState.U||lastState==LastState.UR||lastState==LastState.UL) { r_Yaxis= 1f; }else if(lastState == LastState.D||lastState==LastState.DR||lastState==LastState.DL) { r_Yaxis= -1f; } } else { lastState = getCastAngle(); } getStandAnimation(lastState); ragePixel.PlayNamedAnimation(animation, false); castDirectionSet = true; } //Move the sprite into moveDirection at walkingSpeed pixels/sec //transform.Translate(moveDirection * Time.deltaTime * walkingSpeed); reset(); }
public void OnWeaponBuy(byte wpn_id) { switch (wpn_id) { case 248: return; case 249: return; case 250: return; case 251: return; case 252: //ph.LogConsole("Cannot buy ( wrong team)"); return; case 253: //ph.LogConsole("Not enough money to buy weapon!"); return; case 254: //ph.LogConsole("Cannot buy this weapon! Buytime expired "); return; case 255: //ph.LogConsole("Not in the right area to buy weapon!"); return; default: break; } if (isPrimaryWeapon(wpn_id)) walkingState = WalkingState.EnemySearch; local.Currentweapon = wpn_id; local.Ammo = (short)Weapons.wpns[wpn_id].ammo; local.AmmoIn = (short)Weapons.wpns[wpn_id].ammoIn; }