void Update() { if (finished) { return; } if (resetting) { resetTimer += Time.deltaTime; return; } if (Input.GetAxis("Horizontal") < 0) { currentMoveState = MOVE_STATE.LEFT; } else if (Input.GetAxis("Horizontal") > 0) { currentMoveState = MOVE_STATE.RIGHT; } else { currentMoveState = MOVE_STATE.STILL; } }
public void Init() { while (listPassinger.Count > 0) { var p = listPassinger[0]; p.Dispose(); listPassinger.RemoveAt(0); } textPassinger.text = listPassinger.Count.ToString(); for (int i = 0; i < floorBtnflag.Length; ++i) { floorBtnflag[i] = false; listFloor[i].GetComponent <VerticalLine>().SetDestResquest(false); } currentMoveSpeed = 0; recv_action = MOVE_STATE.Stop; SetDirction(recv_action); nextEvent = Event.None; nextTransitionTime = 0; fsm.SetCurrentState(State.Ready); reqState = State.Ready; reqfloor = -1; reqTime = 0; SetPosFloor(Random.Range(0, ElevatorAcademy.floors)); }
public int SearchRuleBaseNearstElevator(int floor, MOVE_STATE dir) { float min = 1000000f; float dist = 0; int buttonDir = 0; if (dir != MOVE_STATE.Down) { buttonDir = 1; } foreach (var e in listElve) { dist = e.GetFloorDist(floor, dir); if (dist < min) { callReqReserveCar[floor, buttonDir] = e; min = dist; } } if (callReqReserveCar[floor, buttonDir] != null) { var el = callReqReserveCar[floor, buttonDir]; el.SetCallRequest(floor, dir); return(el.GetNo()); } return(-1); }
public bool SetCallRequest(int floor, MOVE_STATE dir) { if (fsm.GetCurrentState() == State.Ready) { if (floor == GetFloor()) { fsm.StateTransition(Event.DoorOpenRequest); SetDirction(dir); return(true); } if (floor > GetFloor()) { SetDirction(MOVE_STATE.Up); } else { SetDirction(MOVE_STATE.Down); } fsm.StateTransition(Event.Call); return(true); } return(false); }
private void Move() { if (unit.isStun) { if (this.curSpeed > 0) { this.curSpeed -= this.decelerationRate * this.speed * TimeManager.Instance.FixedDeltaTime * (1 + factor); } else { this.curSpeed = 0; } return; } switch (this.moveState) { case MOVE_STATE.STOP: return; case MOVE_STATE.ACCELERATE: Accelerate(); break; case MOVE_STATE.MOVE: if (this.speed > this.curSpeed) { this.moveState = MOVE_STATE.ACCELERATE; } break; case MOVE_STATE.DECELERATE: DecelerateForArrive(); break; default: Debug.LogError("MoveState is Incorrect!"); return; } /* 목적지에 가까워졌을 때, 방향이 바뀌는 것을 방지하기 위해 조건문 추가 */ if (this.moveState != MOVE_STATE.DECELERATE) { this.moveDir = this.destination.SubtractVector3FromVector2(this.cachedTransform.position); } float distanceToDest = moveDir.sqrMagnitude; this.moveDir.Normalize(); this.cachedTransform.Translate(moveDir * this.curSpeed * TimeManager.Instance.FixedDeltaTime); //if (this.moveState != MOVE_STATE.DECELERATE && this.moveState != MOVE_STATE.STOP && // distanceToDest <= MathHelpers.DecelerateDistance(this.decelerationRate, this.curSpeed)) //{ // this.moveState = MOVE_STATE.DECELERATE; //} if (this.moveState != MOVE_STATE.DECELERATE && this.moveState != MOVE_STATE.STOP && distanceToDest <= decelerationDistance) { this.moveState = MOVE_STATE.DECELERATE; } }
public void StopGrapplingHook() { if (moveState == MOVE_STATE.GRAPPLING_HOOK) { moveState = MOVE_STATE.ON_GROUND; DoJump(); } }
/// <summary>목적지를 설정하고, MoveState를 ACCELERATE상태로 바꿉니다.</summary> public void SetDestination(Vector3 pos, Action <bool> callback = null) { this.destination = BoardManager.instance.ClampToBoard(pos, CLAMP_BOARD_SIZE_X, CLAMP_BOARD_SIZE_Y);//목적지 보드 제한 this.onArrivedCallback = callback; this.moveState = MOVE_STATE.ACCELERATE; unit.animator.SetBool("isWalk", true); decelerationDistance = Mathf.Max(0.1f, Mathf.InverseLerp(Vector2.Distance(cachedTransform.position, pos), 0, decelerationRate)); }
public void DoJump() { if (moveState == MOVE_STATE.ON_GROUND) { timeSinceJumpStart = 0f; moveState = MOVE_STATE.JUMPING; } }
private void Accelerate() { this.curSpeed += this.accelerationRate * this.speed * TimeManager.Instance.FixedDeltaTime * (1 + factor); if (this.curSpeed >= this.speed) { this.curSpeed = this.speed; this.moveState = MOVE_STATE.MOVE; } }
// Update is called once per frame private void FixedUpdate() { Vector3 moveVector = Vector3.zero; if (moveState == MOVE_STATE.GRAPPLING_HOOK) { Vector3 moveDir = grappleHookTarget - transform.position; //Vector3 finalMoveDir = Vector3.ClampMagnitude(moveDir, grapplingHookSpeed); Vector3 finalMoveDir = moveDir.normalized * grapplingHookSpeed; moveVector += finalMoveDir; } else { if (moveState == MOVE_STATE.JUMPING) { if (timeSinceJumpStart < jumpDuration) { timeSinceJumpStart += Time.deltaTime; moveVector += Vector3.up * jumpHeight * (jumpDuration - timeSinceJumpStart); } else if (charController.isGrounded) { moveState = MOVE_STATE.ON_GROUND; } } Vector3 nonJumpMovement = Vector3.zero; for (int move = 0; move < momentVectors.Length; ++move) { nonJumpMovement += momentVectors[move] * moveSpeed; } nonJumpMovement.y = 0; moveVector += nonJumpMovement; moveVector += Physics.gravity; } MoveChar(moveVector); if (moveVector != Vector3.zero) { // Send data to the Server fpsPlayer.SetPlayerPosn(transform.position); } for (int move = 0; move < momentVectors.Length; ++move) { momentVectors[move] = Vector3.zero; } }
void Start() { target = FindObjectOfType <Player>().GetComponent <Transform>(); moveState = MOVE_STATE.E_SPAWN_MOVE; curMovePoint = 0; bFinishedMove = true; enemyRenderer = gameObject.GetComponent <Renderer>(); enemyRenderer.enabled = false; }
public void SetButton(MOVE_STATE dir, bool bOn) { textCallButton[(int)dir].gameObject.SetActive(bOn); if (bOn) { building.CallRequest(floorNo, dir); } }
public bool IsCallRequest(MOVE_STATE dir) { if (textCallButton[(int)dir] == null || !textCallButton[(int)dir].gameObject.activeSelf) return false; return true; }
/// <summary>유닛을 즉시 멈춥니다.</summary> public void Stop() { this.curSpeed = 0.0f; this.moveState = MOVE_STATE.STOP; unit.animator.SetBool("isWalk", false); this.moveDir = new Vector2(0.0f, 0.0f); if (this.onArrivedCallback != null) { this.onArrivedCallback(false); } }
private float mGoalZ; // 目標とするz座標 /// <summary> /// mMoveState==DEFAULTの場合に、目標とするz座標を計算する /// </summary> public void DecideMovement() { if (mMoveState == MOVE_STATE.DEFAULT) { // 現在のz座標を取得 float currentZ = mTrans.position.z; // 移動可能なz軸の範囲から乱数取得 float rand = Random.Range(-14.0f, 15.0f); // 取得した乱数と現在のz座標の距離を計算 float difference = 0.0f; if (currentZ >= rand) { difference = Mathf.Abs(currentZ - rand); mMoveState = MOVE_STATE.DOWN; } else { difference = Mathf.Abs(rand - currentZ); mMoveState = MOVE_STATE.UP; } // 距離が1.0f以上あるならば目標の座標を決定し、そうでないならば次フレームまでその場で待機 if (difference >= 1.0f) { mGoalZ = rand; } else { mMoveState = MOVE_STATE.DEFAULT; } // mMoveStateを条件にして、TankMovementの移動メソッドを呼び出す switch (mMoveState) { case MOVE_STATE.DEFAULT: mMoveScript.ResetVelocity(); break; case MOVE_STATE.UP: mMoveScript.SetVelocityUp(); break; case MOVE_STATE.DOWN: mMoveScript.SetVelocityDown(); break; } } }
private void DecelerateForArrive() { this.curSpeed -= this.decelerationRate * (this.curSpeed + this.speed) * 0.5f * TimeManager.Instance.FixedDeltaTime * (1 + factor); if (this.curSpeed <= 0.0f) { this.curSpeed = 0.0f; this.moveState = MOVE_STATE.STOP; unit.animator.SetBool("isWalk", false); if (this.onArrivedCallback != null) { this.onArrivedCallback(true); } this.moveDir = new Vector2(0.0f, 0.0f); } }
public void SetDirction(MOVE_STATE dir) { up.SetActive(false); down.SetActive(false); moveDirState = dir; if (dir == MOVE_STATE.Down) { down.SetActive(true); } else if (dir == MOVE_STATE.Up) { up.SetActive(true); } }
public void CallRequest(int floor, MOVE_STATE dir) { switch (centerCtrlAgent.brain.brainType) { case BrainType.Player: case BrainType.Heuristic: SearchRuleBaseNearstElevator(floor, dir); break; case BrainType.External: case BrainType.Internal: break; default: break; } }
public void CallRequest(int floor, MOVE_STATE dir) { //switch(elevatorBrain.brainType) //{ // case BrainType.Player: // case BrainType.Heuristic: // SearchRuleBaseNearstElevator(floor, dir); // break; // case BrainType.External: // case BrainType.Internal: // break; // default: // break; //} }
public void MoveStop() { int floor = (int)GetFloor(); var f = building.GetFloor(floor); if (floorBtnflag[floor] || f.IsCallRequest(GetMoveState())) { fsm.StateTransition(Event.DoorOpenRequest); } else if (listPassinger.Count == 0 && f.listPassinger.Count > 0) { if (GetMoveState() == MOVE_STATE.Down) { moveDirState = MOVE_STATE.Up; } else { moveDirState = MOVE_STATE.Down; } fsm.StateTransition(Event.DoorOpenRequest); } else if (listPassinger.Count == 0 && f.listPassinger.Count == 0) { fsm.StateTransition(Event.EmptyPassinger); } else { fsm.StateTransition(Event.DoorCloseEnd); } SetFloorButton(floor, false); if (requestFloor == floor) { requestFloor = -1; } }
private IEnumerator Move() { STATE = MOVE_STATE.LEFT; while (true) { var r = Random.Range(1, 3); var y = Random.Range(0.675f, 1.5f); var t = 0f; var position = transform.position; yield return(new WaitForSeconds(r)); if (STATE == MOVE_STATE.LEFT) { var x = Random.Range(-1.5f, -0.5f); while (t <= 2f) { t += Time.deltaTime; yield return(null); transform.position = Vector3.Lerp(position, new Vector3(x, y, 0), t / 2f); } STATE = MOVE_STATE.RIGHT; } else { var x = Random.Range(0.5f, 1.5f); while (t <= 2f) { t += Time.deltaTime; yield return(null); transform.position = Vector3.Lerp(position, new Vector3(x, y, 0), t / 2f); } STATE = MOVE_STATE.LEFT; } } }
public void Init(UnitData data) { SetSpeed(data.moveSpeed); if (unit.data.accelerationRate == 0.0f) { this.accelerationRate = 0.5f; } else { this.accelerationRate = unit.data.accelerationRate; } if (unit.data.decelerationRate == 0.0f) { this.decelerationRate = 1.0f; } else { this.decelerationRate = unit.data.decelerationRate; } moveState = MOVE_STATE.STOP; curSpeed = 0; }
/// <summary> /// 移動の完了判定 /// 移動完了の判定を行い、完了しているならばmMoveStateをDEFAULTに戻す /// </summary> public void CheckMovement() { float currentZ = mTrans.position.z; switch (mMoveState) { case MOVE_STATE.DEFAULT: return; case MOVE_STATE.UP: if (currentZ >= mGoalZ) { mMoveState = MOVE_STATE.DEFAULT; } break; case MOVE_STATE.DOWN: if (currentZ <= mGoalZ) { mMoveState = MOVE_STATE.DEFAULT; } break; } }
public float GetFloorDist(int floor, MOVE_STATE dir) { float dist = listFloor[floor].transform.position.y - car.transform.position.y; if (moveDirState == (int)MOVE_STATE.Stop) { return(Mathf.Abs(dist)); } if (moveDirState == MOVE_STATE.Up) { if (dist > 0) { return(Mathf.Abs(dist)); } else { dist = Mathf.Abs(listFloor[ElevatorAcademy.floors - 1].transform.position.y - car.transform.position.y); dist += Mathf.Abs(listFloor[ElevatorAcademy.floors - 1].transform.position.y - listFloor[floor].transform.position.y); return(dist); } } if (dist < 0) { return(Mathf.Abs(dist)); } else ///내려올경우.. { dist = Mathf.Abs(listFloor[0].transform.position.y - car.transform.position.y); dist += Mathf.Abs(listFloor[0].transform.position.y - listFloor[floor].transform.position.y); } return(dist); }
public void AgentThreeAction(float[] vectorAction, string textAction) { AddReward(-0.01f); recv_action = (MOVE_STATE)Mathf.FloorToInt(vectorAction[0]); reqfloor = -1; int floor, nextfloor; GetFloor(out floor, out nextfloor); var f = building.GetFloor(nextfloor); switch (recv_action) { case MOVE_STATE.Stop: { if (fsm.GetCurrentState() == State.NormalMove) { if (listPassenger.Count == 0 && f.listPassenger.Count > 0) { AddReward(0.01f); } } else if (fsm.GetCurrentState() == State.Ready) { while (true && f.listPassenger.Count > 0) { MOVE_STATE dir = (MOVE_STATE)Random.Range((int)MOVE_STATE.Down, (int)MOVE_STATE.end); if (f.IsCallRequest(dir)) { fsm.StateTransition(Event.DoorOpenRequest); SetDirction(dir); return; } } } } fsm.StateTransition(Event.DecelerateStart); return; break; case MOVE_STATE.Down: if (floor == 0) { AddReward(-0.01f); return; } if (GetMoveState() != recv_action) { if (listPassenger.Count > 0) { if (currentMoveSpeed > 0.0f) //이동 { AddReward(-0.005f); return; } } else if (currentMoveSpeed > 0.0f) { fsm.StateTransition(Event.DecelerateStart); return; } } if (!floorBtnflag[nextfloor] && f.listPassenger.Count == 0) { AddReward(0.02f); } else if (floorBtnflag[nextfloor] || f.IsCallRequest(recv_action)) { AddReward(-0.042f); } if (moveDirState != recv_action) { if (floor != 0 && listPassenger.Count > 0 && moveDirState != MOVE_STATE.Stop) { AddReward(-0.04f); return; } } SetDirction(recv_action); fsm.StateTransition(Event.Call); break; case MOVE_STATE.Up: if (floor == (ElevatorAcademy.floors - 1)) { AddReward(-0.01f); return; } if (GetMoveState() != recv_action) { if (listPassenger.Count > 0) { if (currentMoveSpeed > 0.0f) //이동 { AddReward(-0.005f); return; } } else if (currentMoveSpeed > 0.0f) { fsm.StateTransition(Event.DecelerateStart); return; } } if (!floorBtnflag[nextfloor] && f.listPassenger.Count == 0) { AddReward(0.02f); } else if (floorBtnflag[nextfloor] || f.IsCallRequest(recv_action)) { AddReward(-0.04f); } if (moveDirState != recv_action) { if (floor != (ElevatorAcademy.floors - 1) && listPassenger.Count > 0 && moveDirState != MOVE_STATE.Stop) { AddReward(-0.04f); return; } } SetDirction(recv_action); fsm.StateTransition(Event.Call); break; } }
public void SetMoveState(MOVE_STATE value) { moveState = value; }
private void Awake() { STATE = MOVE_STATE.IDLE; StartCoroutine(Move()); }
public void StartGrapplingHook(Vector3 grapplingPosn) { moveState = MOVE_STATE.GRAPPLING_HOOK; grappleHookTarget = grapplingPosn; }
void Update() { if (OfflineManager.isPlaying) { /* --------------------------------- * AP, HP関係 * ---------------------------------- */ if (OfflineManager.apPlus) { ap++; } if (ap > PhotonManager.MAXAP) { ap = PhotonManager.MAXAP; } else if (ap < 0) { ap = 0; } if (hp == 0) { GameObject.Find("OfflineManager").SendMessage("BattleEnd", gameObject.tag); } hpbar.fillAmount = (float)hp / PhotonManager.MAXHP; hpbarText.text = "HP " + hp + " / " + PhotonManager.MAXHP; apbar.fillAmount = (float)ap / PhotonManager.MAXAP; apbarText.text = "AP " + ap + " / " + PhotonManager.MAXAP; AP_PROB = (float)ap / PhotonManager.MAXAP; /* --------------------------------- * 敵のいる位置に合わせて向き変更 * ---------------------------------- */ myPos = myPlayer.transform.position.x; // 位置が重なってる時向きが変わりまくってガタガタするのを防止 if (Mathf.Abs(transform.position.x - myPos) > 0.2f) { if (transform.position.x > myPos) { transform.eulerAngles = new Vector3(0, -90, 0); } else { transform.eulerAngles = new Vector3(0, 90, 0); } } /* --------------------------------- * キャラ同士が乗っかりあってしまった時、AIが動くことで重なりを回避 * ---------------------------------- */ if (Mathf.Abs(transform.position.x - myPos) < 0.3f && Mathf.Abs(transform.position.y - myPlayer.transform.position.y) < 1.03f) { isOver = true; } else { isOver = false; } /* --------------------------------- * 基本は毎秒行動選択を更新 * 相手の攻撃モーション時には即更新が入る * ---------------------------------- */ if (isOver) { /* --------------------------------- * キャラの重なり合いが起きている時は回避を行う * --------------------------------- */ if (ap >= PhotonManager.AvoidAP) { ap -= PhotonManager.AvoidAP; if (transform.position.x > 0) { transform.position = new Vector3(-3, transform.position.y, 0); Instantiate(Resources.Load("AvoidEffect/AvoidEffectLeft" + chara) as GameObject, new Vector3(-2, transform.position.y, -1), Quaternion.identity); } else { transform.position = new Vector3(3, transform.position.y, 0); Instantiate(Resources.Load("AvoidEffect/AvoidEffectRight" + chara) as GameObject, new Vector3(2, transform.position.y, -1), Quaternion.identity); } audios_SE[5].Play(); moveState = MOVE_STATE.stopping; idleFlg = true; } else { moveState = MOVE_STATE.fleeing; walkFlg = true; } if (timer == 0) { timer = 1.1f; } // --------------------------------- } else { if (myAttacked) { timer = 0; } else { if (timer > 1) { timer = 0; } else { timer += Time.deltaTime; } } } /* --------------------------------- * timer == 0の時、行動選択を更新 * ---------------------------------- */ if (timer == 0) { /* --------------------------------- * 相手の攻撃モーション発生時 * ---------------------------------- */ if (myAttacked) { // 回避率と距離によって回避が発生 if (ap >= PhotonManager.AvoidAP && Random.Range(0.0f, 1.0f) < AVOID_PROB && Mathf.Abs(transform.position.x - myPos) < 1f) { ap -= PhotonManager.AvoidAP; if (transform.position.x > 0) { transform.position = new Vector3(-3, transform.position.y, 0); Instantiate(Resources.Load("AvoidEffect/AvoidEffectLeft" + chara) as GameObject, new Vector3(-2, transform.position.y, -1), Quaternion.identity); } else { transform.position = new Vector3(3, transform.position.y, 0); Instantiate(Resources.Load("AvoidEffect/AvoidEffectRight" + chara) as GameObject, new Vector3(2, transform.position.y, -1), Quaternion.identity); } audios_SE[5].Play(); moveState = MOVE_STATE.stopping; idleFlg = true; } else { // 回避が発生しなかった場合は一定確率でジャンプ発生 if (isGround) { if (Random.Range(0.0f, 1.0f) < JUMP_PROB) { Jump(); } } } timer = 0.5f; // --------------------------------- /* --------------------------------- * 通常行動 * ---------------------------------- */ } else { /* --------------------------------- * 残りHPを考慮した確率と距離によってスキル発動 * ---------------------------------- */ if (hp > PhotonManager.SkillOwnDamage && 2.5f < Mathf.Abs(transform.position.x - myPos) && Mathf.Abs(transform.position.x - myPos) < 4.5f) { // 残りHPの割合分だけ、スキル発生確率が下がる // HP最大時 => スキル確率20 * 1.0 = 20% // HP半分時 => スキル確率20 * 0.5 = 10% float HP_PROB = (float)hp / PhotonManager.MAXHP; if (Random.Range(0.0f, 1.0f) < SKILL_PROB * HP_PROB) { hp -= PhotonManager.SkillOwnDamage; animator.SetTrigger("Skill"); psSkill.transform.position = new Vector3(transform.position.x, 0, 0); psSkill.GetComponent <ParticleSystem>().Play(); audios_SE[3].Play(); audios_SE[4].PlayDelayed(0.5f); skillFlg = true; moveState = MOVE_STATE.stopping; idleFlg = true; } } // --------------------------------- /* --------------------------------- * スキルが発動しなければ移動のみか通常攻撃 * ---------------------------------- */ if (!skillFlg) { /* --------------------------------- * 距離が離れている時は攻撃積極性により追いかける * ---------------------------------- */ if (Mathf.Abs(transform.position.x - myPos) > 1) { // 一定確率でジャンプ発生 if (isGround) { if (Random.Range(0.0f, 1.0f) < JUMP_PROB) { Jump(); } } if (Random.Range(0.0f, 1.0f) < ATTACK_PROB) { moveState = MOVE_STATE.chasing; walkFlg = true; } else { moveState = MOVE_STATE.stopping; idleFlg = true; } // --------------------------------- /* --------------------------------- * 距離が近い時、近距離攻撃or移動のみ * ---------------------------------- */ } else { // 一定確率でジャンプ発生 if (isGround) { if (Random.Range(0.0f, 1.0f) < JUMP_PROB) { Jump(); } } /* --------------------------------- * 攻撃積極性によってさらに近づくか一度離れるかが決まる * ---------------------------------- */ if (Random.Range(0.0f, 1.0f) < ATTACK_PROB) { moveState = MOVE_STATE.chasing; walkFlg = true; /* --------------------------------- * 残りAPを考慮した確率によって攻撃 * 攻撃をしなかったら攻撃積極性により後退 * ---------------------------------- */ float rand = Random.Range(0.0f, 1.0f); // 60%でSmallAttack if (rand < 0.6f) { if (ap >= PhotonManager.SmallAttackAP && Random.Range(0.0f, 1.0f) < AP_PROB) { ap -= PhotonManager.SmallAttackAP; animator.SetTrigger("SmallAttack"); if (transform.position.x > myPos) { psSmallLeft.Play(); } else { psSmallRight.Play(); } audios_SE[2].Play(); } else { if (Random.Range(0.0f, 1.0f) > ATTACK_PROB) { moveState = MOVE_STATE.fleeing; } } // 40%でBigAttack } else { if (ap >= PhotonManager.BigAttackAP && Random.Range(0.0f, 1.0f) < AP_PROB) { ap -= PhotonManager.BigAttackAP; animator.SetTrigger("BigAttack"); if (transform.position.x > myPos) { psBigLeft.Play(); } else { psBigRight.Play(); } audios_SE[2].Play(); } else { if (Random.Range(0.0f, 1.0f) > ATTACK_PROB) { moveState = MOVE_STATE.fleeing; } } } // --------------------------------- } else { moveState = MOVE_STATE.fleeing; walkFlg = true; } // --------------------------------- } } } myAttacked = false; skillFlg = false; } // 移動範囲外に出たら止まる if (transform.position.x < -3) { moveState = MOVE_STATE.stopping; idleFlg = true; transform.position = new Vector3(-3, transform.position.y, transform.position.z); } else if (3 < transform.position.x) { moveState = MOVE_STATE.stopping; idleFlg = true; transform.position = new Vector3(3, transform.position.y, transform.position.z); } switch (moveState) { case MOVE_STATE.chasing: if (transform.position.x - myPos < 0) { direction = 1f; } else { direction = -1f; } animator.SetTrigger("Walk"); if (walkFlg) { audios_SE[0].Play(); walkFlg = false; } break; case MOVE_STATE.fleeing: if (transform.position.x - myPos < 0) { direction = -1f; } else { direction = 1f; } animator.SetTrigger("Walk"); if (walkFlg) { audios_SE[0].Play(); walkFlg = false; } break; case MOVE_STATE.stopping: direction = 0; animator.SetTrigger("Idle"); if (idleFlg) { audios_SE[0].Stop(); idleFlg = false; } break; } rigid.velocity = new Vector3(scroll * direction, rigid.velocity.y, 0); } }
public void AgentThreeAction(float[] vectorAction, string textAction, out float reward) { reward = 0f; reward += -0.01f; recv_action = (MOVE_STATE)Mathf.FloorToInt(vectorAction[0]); int floor, nextfloor; GetFloor(out floor, out nextfloor); var f = building.GetFloor(nextfloor); switch (recv_action) { case MOVE_STATE.Stop: if (fsm.GetCurrentState() == State.NormalMove) { int lllll = 0; if (listPassinger.Count == 0 && f.listPassinger.Count > 0) { reward += 0.1f; } else if (listPassinger.Count == 0 && f.listPassinger.Count == 0) { reward += -0.05f; } } else if (fsm.GetCurrentState() == State.Ready) { while (true && f.listPassinger.Count > 0) { MOVE_STATE dir = (MOVE_STATE)Random.Range((int)MOVE_STATE.Down, (int)MOVE_STATE.end); if (f.IsCallRequest(dir)) { fsm.StateTransition(Event.Arrived); SetDirction(dir); return; } } } fsm.StateTransition(Event.DecelerateStart); return; case MOVE_STATE.Down: if (GetMoveState() != recv_action) { if (currentMoveSpeed > 0.0f) //이동 { reward += -0.01f; return; } } if (floor == 0) { SetDirction(MOVE_STATE.Up); reward += -0.05f; } if (floorBtnflag[nextfloor]) { fsm.StateTransition(Event.DecelerateStart); return; } { SetDirction(recv_action); fsm.StateTransition(Event.Call); } break; case MOVE_STATE.Up: if (GetMoveState() != recv_action) { if (currentMoveSpeed > 0.0f) //이동 { reward += -0.01f; return; } } if (floor == (ElevatorAcademy.floors - 1)) { SetDirction(MOVE_STATE.Down); reward += -0.05f; //fsm.StateTransition(Event.Arrived); // return; } if (floorBtnflag[nextfloor]) { fsm.StateTransition(Event.DecelerateStart); return; //AddReward(-0.05f); } SetDirction(recv_action); fsm.StateTransition(Event.Call); SetDirction(recv_action); fsm.StateTransition(Event.Call); break; } }