private void DidJump() { this.jumping = true; this.jumpingReachedApex = false; this.lastJumpTime = Time.time; this.lastJumpButtonTime = -10f; this._characterState = PickupCharacterState.Jumping; }
void DidJump() { jumping = true; jumpingReachedApex = false; lastJumpTime = Time.time; //lastJumpStartHeight = transform.position.y; lastJumpButtonTime = -10; _characterState = PickupCharacterState.Jumping; }
public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info) { if (stream.isWriting) { stream.SendNext(base.transform.position); stream.SendNext((byte)this._characterState); } else { bool flag = this.remotePosition == Vector3.zero; this.remotePosition = (Vector3)stream.ReceiveNext(); this._characterState = (PickupCharacterState)((byte)stream.ReceiveNext()); if (flag) { base.transform.position = this.remotePosition; } } }
public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info) { if (stream.isWriting) { stream.SendNext(this.transform.position); stream.SendNext((byte)this._characterState); } else { bool initialRemotePosition = (remotePosition == Vector3.zero); remotePosition = (Vector3)stream.ReceiveNext(); this._characterState = (PickupCharacterState)((byte)stream.ReceiveNext()); if (initialRemotePosition) { // avoids lerping the character from "center" to the "current" position when this client joins this.transform.position = remotePosition; } } }
void UpdateSmoothedMovementDirection() { Transform cameraTransform = Camera.main.transform; bool grounded = IsGrounded(); // Forward vector relative to the camera along the x-z plane Vector3 forward = cameraTransform.TransformDirection(Vector3.forward); forward.y = 0; forward = forward.normalized; // Right vector relative to the camera // Always orthogonal to the forward vector Vector3 right = new Vector3(forward.z, 0, -forward.x); float v = Input.GetAxisRaw("Vertical"); float h = Input.GetAxisRaw("Horizontal"); // Are we moving backwards or looking backwards if (v < -0.2f) { movingBack = true; } else { movingBack = false; } bool wasMoving = isMoving; isMoving = Mathf.Abs(h) > 0.1f || Mathf.Abs(v) > 0.1f; // Target direction relative to the camera Vector3 targetDirection = h * right + v * forward; // Debug.Log("targetDirection " + targetDirection); // Grounded controls if (grounded) { // Lock camera for short period when transitioning moving & standing still lockCameraTimer += Time.deltaTime; if (isMoving != wasMoving) { lockCameraTimer = 0.0f; } // We store speed and direction seperately, // so that when the character stands still we still have a valid forward direction // moveDirection is always normalized, and we only update it if there is user input. if (targetDirection != Vector3.zero) { // If we are really slow, just snap to the target direction if (moveSpeed < walkSpeed * 0.9f && grounded) { moveDirection = targetDirection.normalized; } // Otherwise smoothly turn towards it else { moveDirection = Vector3.RotateTowards(moveDirection, targetDirection, rotateSpeed * Mathf.Deg2Rad * Time.deltaTime, 1000); moveDirection = moveDirection.normalized; } } // Smooth the speed based on the current target direction float curSmooth = speedSmoothing * Time.deltaTime; // Choose target speed //* We want to support analog input but make sure you cant walk faster diagonally than just forward or sideways float targetSpeed = Mathf.Min(targetDirection.magnitude, 1.0f); _characterState = PickupCharacterState.Idle; // Pick speed modifier if ((Input.GetKey(KeyCode.LeftShift) | Input.GetKey(KeyCode.RightShift)) && isMoving) { targetSpeed *= runSpeed; _characterState = PickupCharacterState.Running; } else if (Time.time - trotAfterSeconds > walkTimeStart) { targetSpeed *= trotSpeed; _characterState = PickupCharacterState.Trotting; } else if (isMoving) { targetSpeed *= walkSpeed; _characterState = PickupCharacterState.Walking; } moveSpeed = Mathf.Lerp(moveSpeed, targetSpeed, curSmooth); // Reset walk time start when we slow down if (moveSpeed < walkSpeed * 0.3f) { walkTimeStart = Time.time; } } // In air controls else { // Lock camera while in air if (jumping) { lockCameraTimer = 0.0f; } if (isMoving) { inAirVelocity += targetDirection.normalized * Time.deltaTime * inAirControlAcceleration; } } }
void UpdateSmoothedMovementDirection() { Transform cameraTransform = Camera.main.transform; bool grounded = IsGrounded(); // Forward vector relative to the camera along the x-z plane Vector3 forward = cameraTransform.TransformDirection(Vector3.forward); forward.y = 0; forward = forward.normalized; // Right vector relative to the camera // Always orthogonal to the forward vector Vector3 right = new Vector3(forward.z, 0, -forward.x); float v = Input.GetAxisRaw("Vertical"); float h = Input.GetAxisRaw("Horizontal"); // Are we moving backwards or looking backwards if (v < -0.2f) movingBack = true; else movingBack = false; bool wasMoving = isMoving; isMoving = Mathf.Abs(h) > 0.1f || Mathf.Abs(v) > 0.1f; // Target direction relative to the camera Vector3 targetDirection = h * right + v * forward; // Debug.Log("targetDirection " + targetDirection); // Grounded controls if (grounded) { // Lock camera for short period when transitioning moving & standing still lockCameraTimer += Time.deltaTime; if (isMoving != wasMoving) lockCameraTimer = 0.0f; // We store speed and direction seperately, // so that when the character stands still we still have a valid forward direction // moveDirection is always normalized, and we only update it if there is user input. if (targetDirection != Vector3.zero) { // If we are really slow, just snap to the target direction if (moveSpeed < walkSpeed * 0.9f && grounded) { moveDirection = targetDirection.normalized; } // Otherwise smoothly turn towards it else { moveDirection = Vector3.RotateTowards(moveDirection, targetDirection, rotateSpeed * Mathf.Deg2Rad * Time.deltaTime, 1000); moveDirection = moveDirection.normalized; } } // Smooth the speed based on the current target direction float curSmooth = speedSmoothing * Time.deltaTime; // Choose target speed //* We want to support analog input but make sure you cant walk faster diagonally than just forward or sideways float targetSpeed = Mathf.Min(targetDirection.magnitude, 1.0f); _characterState = PickupCharacterState.Idle; // Pick speed modifier if ((Input.GetKey(KeyCode.LeftShift) | Input.GetKey(KeyCode.RightShift)) && isMoving) { targetSpeed *= runSpeed; _characterState = PickupCharacterState.Running; } else if (Time.time - trotAfterSeconds > walkTimeStart) { targetSpeed *= trotSpeed; _characterState = PickupCharacterState.Trotting; } else if (isMoving) { targetSpeed *= walkSpeed; _characterState = PickupCharacterState.Walking; } moveSpeed = Mathf.Lerp(moveSpeed, targetSpeed, curSmooth); // Reset walk time start when we slow down if (moveSpeed < walkSpeed * 0.3f) walkTimeStart = Time.time; } // In air controls else { // Lock camera while in air if (jumping) lockCameraTimer = 0.0f; if (isMoving) inAirVelocity += targetDirection.normalized * Time.deltaTime * inAirControlAcceleration; } }
private void UpdateSmoothedMovementDirection() { Transform transform = Camera.main.transform; bool flag = this.IsGrounded(); Vector3 a = transform.TransformDirection(Vector3.forward); a.y = 0f; a = a.normalized; Vector3 a2 = new Vector3(a.z, 0f, -a.x); float axisRaw = Input.GetAxisRaw("Vertical"); float axisRaw2 = Input.GetAxisRaw("Horizontal"); if (axisRaw < -0.2f) { this.movingBack = true; } else { this.movingBack = false; } bool flag2 = this.isMoving; this.isMoving = (Mathf.Abs(axisRaw2) > 0.1f || Mathf.Abs(axisRaw) > 0.1f); Vector3 vector = axisRaw2 * a2 + axisRaw * a; if (flag) { this.lockCameraTimer += Time.deltaTime; if (this.isMoving != flag2) { this.lockCameraTimer = 0f; } if (vector != Vector3.zero) { if (this.moveSpeed < this.walkSpeed * 0.9f && flag) { this.moveDirection = vector.normalized; } else { this.moveDirection = Vector3.RotateTowards(this.moveDirection, vector, this.rotateSpeed * 0.0174532924f * Time.deltaTime, 1000f); this.moveDirection = this.moveDirection.normalized; } } float t = this.speedSmoothing * Time.deltaTime; float num = Mathf.Min(vector.magnitude, 1f); this._characterState = PickupCharacterState.Idle; if ((Input.GetKey(KeyCode.LeftShift) | Input.GetKey(KeyCode.RightShift)) && this.isMoving) { num *= this.runSpeed; this._characterState = PickupCharacterState.Running; } else if (Time.time - this.trotAfterSeconds > this.walkTimeStart) { num *= this.trotSpeed; this._characterState = PickupCharacterState.Trotting; } else if (this.isMoving) { num *= this.walkSpeed; this._characterState = PickupCharacterState.Walking; } this.moveSpeed = Mathf.Lerp(this.moveSpeed, num, t); if (this.moveSpeed < this.walkSpeed * 0.3f) { this.walkTimeStart = Time.time; } } else { if (this.jumping) { this.lockCameraTimer = 0f; } if (this.isMoving) { this.inAirVelocity += vector.normalized * Time.deltaTime * this.inAirControlAcceleration; } } }