void UpdateRotation() { if (m_Motor == null) { return; } if (m_CurFaceDirection != Vector3.zero) { m_Motor.desiredFacingDirection = m_CurFaceDirection.normalized; } else if (m_CurMovementDirection != Vector3.zero) { m_Motor.desiredFacingDirection = m_CurMovementDirection.normalized; } else { m_Motor.desiredFacingDirection = Vector3.zero; } //Vector3 direction = m_CurFaceDirection != Vector3.zero ? m_CurFaceDirection : m_CurMovementDirection; Vector3 direction = m_Motor.desiredFacingDirection; //Debug.DrawRay(m_Motor.transform.position, direction.normalized * 16f, Color.blue); Vector3 velocity = Quaternion.Inverse(m_Motor.transform.rotation) * direction; if (PEUtil.SqrMagnitudeH(velocity) > 0.05f * 0.05f) { m_Animator.SetFloat("Angle", Mathf.Atan2(velocity.x, velocity.z) * 180.0f / 3.14159f); } else { m_Animator.SetFloat("Angle", 0.0f); } PEMotorPhysics motorPhysic = m_Motor as PEMotorPhysics; if (motorPhysic != null) { float rotationSpeed = m_Attribute.GetAttribute(AttribType.RotationSpeed); if (motorPhysic.velocity.sqrMagnitude > 0.25f * 0.25f) { if (m_SpeedState == SpeedState.Walk) { rotationSpeed = motorPhysic.walkSmoothSpeed; } else { rotationSpeed = motorPhysic.runSmoothSpeed; } } if (m_Animator != null) { float rotAnimSpeed = m_Animator.GetFloat("RotationSpeed"); rotationSpeed = rotAnimSpeed > 0.0f ? rotAnimSpeed : rotationSpeed; } motorPhysic.maxRotationSpeed = rotationSpeed; } }
void CalculateMovement() { CalculateDestination(); if (AstarPath.active != null && m_Path != null) { m_Path.SetTargetposition(m_CurMoveDestination); } Vector3 movement = Vector3.zero; if (m_MoveDirection != Vector3.zero) { movement = m_MoveDirection; } else { if (m_CurMoveDestination == Vector3.zero) { movement = Vector3.zero; } else { if (m_Path != null && m_Motor.gravity > PETools.PEMath.Epsilon && AstarPath.active != null) { movement = m_Path.CalculateVelocity(m_Motor.transform.position); } if (movement == Vector3.zero) { movement = m_CurMoveDestination - m_Motor.transform.position; } } } CalculateAvoid(movement); movement = movement.normalized + m_CurAvoidDirection.normalized; if (movement == Vector3.zero) { m_CurMovementDirection = Vector3.zero; } else { if (m_CurMovementDirection == Vector3.zero) { m_CurMovementDirection = movement; } else { //m_CurMovementDirection = Util.ConstantSlerp(m_CurMovementDirection, movement, 90.0f * Time.deltaTime); Vector3 v1 = m_CurMovementDirection; v1.y = 0.0f; Vector3 v2 = movement; v2.y = 0.0f; Vector3 v3 = Util.ConstantSlerp(v1, v2, 90 * Time.deltaTime); m_CurMovementDirection = Quaternion.FromToRotation(v2, v3) * movement; } } if (m_CurMovementDirection == Vector3.zero || !CanMove()) { m_CurMovement = Vector3.zero; } else { if (m_MoveDirection != Vector3.zero) { m_CurMovement = m_CurMovementDirection; } else { float rotateSpeed = 90f; PEMotorPhysics motorPhysic = m_Motor as PEMotorPhysics; if (motorPhysic != null) { rotateSpeed = m_SpeedState == SpeedState.Walk ? motorPhysic.walkSmoothSpeed : motorPhysic.runSmoothSpeed; } Vector3 v1 = m_Motor.transform.forward; v1.y = 0.0f; Vector3 v2 = m_CurMovementDirection; v2.y = 0.0f; Vector3 v3 = Util.ConstantSlerp(v1, v2, rotateSpeed * Time.deltaTime); m_CurMovement = Quaternion.FromToRotation(v2, v3) * m_CurMovementDirection; } } if (m_CurMoveDestination != Vector3.zero) { Debug.DrawLine(m_Motor.transform.position, m_CurMoveDestination, Color.yellow); } Debug.DrawRay(m_Motor.transform.position, m_CurMovement.normalized * (10.0f + m_PeTrans.radius), Color.red); Debug.DrawRay(m_Motor.transform.position, m_CurMovementDirection.normalized * (6.0f + m_PeTrans.radius), Color.blue); }
public MovementPrison(PeEntity entity, PEMotorPhysics motor, Rigidbody rigid) { m_Entity = entity; m_Motor = motor; m_Rigidbody = rigid; }