public void UpdateFromState(PlayerStateData s) { State = (OTHER_PLAYER_STATE)s.state; _isStrafing = s.isStrafing; TargetMovement = s.position; TargetRotation = s.rotation; }
public void UpdateState(PlayerStateData state) { State = (OTHER_PLAYER_STATE)state.state; isStrafing = state.isStrafing; TargetMovement = state.position; TargetRotation = state.rotation; }
void Update() { if (!Ready || e == null) { return; } if (e.State == GAME_STATE.STATE_WORLD && e.getScene().State == SCENE_STATE.STATE_READY) { if (TargetMovement != null && TargetMovement != Vector3.zero) { transform.position = Vector3.Lerp(transform.position, TargetMovement, Time.fixedDeltaTime * 2.5f); } if (TargetRotation != null) { transform.rotation = Quaternion.Lerp(transform.rotation, TargetRotation, Time.fixedDeltaTime * 2.5f); } if (TargetMovement != Vector3.zero) { Vector3 WorldMovement = transform.position - TargetMovement; float dX = Mathf.Round(Mathf.Clamp(Vector3.Dot(transform.right, WorldMovement), -1.0f, 1.0f) * 10f) / 10f; float dY = Mathf.Round(Mathf.Clamp(Vector3.Dot(transform.forward, WorldMovement), -1.0f, 1.0f) * 10f) / 10f; MovementVector = new Vector2(-dX, -dY); if (State == OTHER_PLAYER_STATE.STATE_RUNNING) { //_Animator.SetBool("Idle", false); _Animator.SetBool("Sprint", true); } else if (State == OTHER_PLAYER_STATE.STATE_WALKING) { //_Animator.SetBool("Idle", false); _Animator.SetBool("Sprint", false); } else if (State == OTHER_PLAYER_STATE.STATE_IDLE) { //_Animator.SetBool("Idle", true); _Animator.SetBool("Sprint", false); _Animator.SetFloat("InputLR", 0); _Animator.SetFloat("InputFB", 0); } if (State != OTHER_PLAYER_STATE.STATE_IDLE) { if (!_isStrafing) { _Animator.SetFloat("InputLR", 0f); //_Animator.SetFloat("Rotating", MovementVector.x); _Animator.SetFloat("InputFB", MovementVector.y); _Animator.SetBool("Strafing", false); } else { _Animator.SetFloat("InputLR", MovementVector.x); _Animator.SetFloat("InputFB", MovementVector.y); _Animator.SetBool("Strafing", true); } } } StatePrevious = State; } }
// Update is called once per frame void Update() { if (e == null) { return; } if (e.State == GAME_STATE.STATE_WORLD && e.getScene().State == SCENE_STATE.STATE_READY) { if (TargetMovement != null && TargetMovement != Vector3.zero) { transform.position = Vector3.Lerp(transform.position, TargetMovement, Time.fixedDeltaTime * 2.5f); } if (TargetRotation != null) { transform.rotation = Quaternion.Lerp(transform.rotation, TargetRotation, Time.fixedDeltaTime * 2.5f); } if (TargetMovement != Vector3.zero) { Vector3 WorldMovement = transform.position - TargetMovement; float dX = Mathf.Round(Mathf.Clamp(Vector3.Dot(transform.right, WorldMovement), -1.0f, 1.0f) * 10f) / 10f; float dY = Mathf.Round(Mathf.Clamp(Vector3.Dot(transform.forward, WorldMovement), -1.0f, 1.0f) * 10f) / 10f; MovementVector = new Vector2(-dX, -dY); if (State == OTHER_PLAYER_STATE.STATE_RUNNING) { _Animator.SetBool("Idle", false); _Animator.SetBool("Sprint", true); } else if (State == OTHER_PLAYER_STATE.STATE_WALKING) { _Animator.SetBool("Idle", false); _Animator.SetBool("Sprint", false); } else if (State == OTHER_PLAYER_STATE.STATE_IDLE) { _Animator.SetBool("Idle", true); _Animator.SetBool("Sprint", false); _Animator.SetFloat("Horizontal", 0); _Animator.SetFloat("Vertical", 0); } if (State != OTHER_PLAYER_STATE.STATE_IDLE) { if (!isStrafing) { _Animator.SetFloat("Horizontal", 0f); _Animator.SetFloat("Rotating", MovementVector.x); _Animator.SetFloat("Vertical", MovementVector.y); _Animator.SetBool("Strafing", false); } else { _Animator.SetFloat("Horizontal", MovementVector.x); _Animator.SetFloat("Vertical", MovementVector.y); _Animator.SetBool("Strafing", true); } } } StatePrevious = State; /* * CheckGroundDistance(); * if (isStrafing) * { * if (Input.GetAxis("Mouse X") != 0.0f) * { * var newRotation = new Vector3(transform.eulerAngles.x, _PlayerCamera.transform.eulerAngles.y, transform.eulerAngles.z); * transform.rotation = Quaternion.Lerp(transform.rotation, Quaternion.Euler(newRotation), 1.0f); * } * _Animator.SetFloat("Rotating", Input.GetAxis("Mouse X")); * _Animator.SetBool("Strafing", true); * } * else * { * _Animator.SetBool("Strafing", false); * if (Input.GetAxis("Horizontal") != 0f) * { * transform.Rotate(0f, Input.GetAxis("Horizontal") * rotationSpeed * Time.deltaTime, 0); * _Animator.SetFloat("Rotating", Movement.x); * Movement.x = 0f; * } * * } * * if (!isGrounded || StatePrevious == PLAYER_STATE.STATE_JUMPING) * { * if (StatePrevious != PLAYER_STATE.STATE_JUMPING) * { * if(groundDistance >= 0.95f) * _Animator.SetBool("Falling", true); * JumpVector = transform.TransformDirection(Movement); * fallingSpeed = (State == PLAYER_STATE.STATE_WALKING) ? walkSpeed : runSpeed; * } * State = PLAYER_STATE.STATE_FALLING; * JumpVector = JumpVector * fallingSpeed * Time.deltaTime; * VerticalMovement -= 0.6f * Time.deltaTime; * if(VerticalMovement < 0 && groundDistance >= 0.95f) * _Animator.SetBool("Falling", true); * JumpVector.y = VerticalMovement; * _Controller.Move(JumpVector); * } * else if (isGrounded) * { * _Animator.SetBool("Falling", false); * VerticalMovement = 0f; * if (Movement == Vector3.zero) * { * State = PLAYER_STATE.STATE_IDLE; * _Animator.SetBool("Idle", true); * _Animator.SetBool("Sprint", false); * } * else if (isSprinting) * { * State = PLAYER_STATE.STATE_RUNNING; * _Animator.SetBool("Idle", false); * _Animator.SetBool("Sprint", true); * } * else * { * State = PLAYER_STATE.STATE_WALKING; * _Animator.SetBool("Idle", false); * _Animator.SetBool("Sprint", false); * } * _Animator.SetFloat("Horizontal", Movement.x); * _Animator.SetFloat("Vertical", Movement.z); * MovementVector = transform.TransformDirection(Movement); * if (MovementVector.magnitude > 1) * MovementVector = Vector3.Normalize(MovementVector); * * if (isJumping) * { * fallingSpeed = (State == PLAYER_STATE.STATE_WALKING) ? walkSpeed : runSpeed; * VerticalMovement = 0.23f; * JumpVector = MovementVector; * } * MovementVector = MovementVector * ((State == PLAYER_STATE.STATE_WALKING) ? walkSpeed : runSpeed) * Time.deltaTime; * if (MovementVector != Vector3.zero) * _Controller.Move(MovementVector); * if (isJumping) * { * if(State == PLAYER_STATE.STATE_IDLE) * _Animator.CrossFadeInFixedTime("Idle_Jump", 0.1f); * if(State == PLAYER_STATE.STATE_WALKING) * _Animator.CrossFadeInFixedTime("Walk_Jump", 0.1f); * if(State == PLAYER_STATE.STATE_RUNNING) * _Animator.CrossFadeInFixedTime("Run_Jump", 0.1f); * State = PLAYER_STATE.STATE_JUMPING; * * } * * } */ } }