Beispiel #1
0
    // Update is called once per frame
    void Update()
    {
        if (waypointScript.GetTurnSpeedLimit() - speedBuffer > body.velocity.magnitude || waypointScript.GetTurnSpeedLimit() == 0)
        {
            Accelerate();
            body.drag = 0.0001f;
        }
        else if (waypointScript.GetTurnSpeedLimit() + speedBuffer < body.velocity.magnitude)
        {
            Brake();
        }
        else
        {
            Vector3 newVelocity = (waypointScript.GetDirection() * body.velocity.magnitude);

            // Assign the new velocity to the rigidbody
            body.velocity = newVelocity;
        }

        // Calculate the current rpm based on the vehicle speed and gear
        rpm = (body.velocity.magnitude / speedCap [currentGear - 1]) * maxRPM;

        // Shift gears based on rpm
        ShiftGears();
    }
Beispiel #2
0
    public void NormalMove(Vector3 vRocketDirection)
    {
        Vector3 v3_movement;
        Vector3 v3_targetDirection;

        // 추적 중이라면 방향을 계산
        if (m_bRun)
        {
            v3_targetDirection = m_WayPoint.GetDirectionToPlayer(transform, m_Player);
        }
        else
        {
            if (m_fThinkingTime > 0)
            {
                if (!IsThinking())
                {
                    // 목표 방향
                    v3_targetDirection = m_WayPoint.GetDirection(transform);
                }
                else
                {
                    v3_targetDirection = Vector3.zero;
                }
            }
            else
            {
                v3_targetDirection = m_WayPoint.GetDirection(transform);
            }
        }

        if (v3_targetDirection != Vector3.zero)
        {
            // 목표 방향을 향해 회전
            m_vMoveDirection = Vector3.Slerp(m_vMoveDirection, v3_targetDirection, m_fRotateSpeed * Time.deltaTime);
            m_vMoveDirection = m_vMoveDirection.normalized;
        }
        else
        {
            m_vMoveDirection = Vector3.zero;
        }

        if (!m_bJumping)
        {
            if (m_bRun)
            {
                m_bRun       = true;
                m_fMoveSpeed = m_iRunSpeed;
            }
            else
            {
                m_bRun       = false;
                m_fMoveSpeed = m_iWalkSpeed;
            }
            if ((Jump(m_vMoveDirection)) && (m_bJumping == false))
            {
                m_bJumping       = true;
                m_fVerticalSpeed = m_fJumpSpeed;
            }
        }

        if (IsGrounded())
        {
            m_fVerticalSpeed = 0.0f;
            m_bJumping       = false;
        }
        else
        {
            m_fVerticalSpeed -= m_fGravity * Time.deltaTime;
        }

        v3_movement  = (m_vMoveDirection * m_fMoveSpeed) + new Vector3(0, m_fVerticalSpeed, 0);
        v3_movement *= Time.deltaTime;
        m_bPrepare   = false;

        if (m_vMoveDirection != Vector3.zero)
        {
            if (m_fMoveSpeed == m_iWalkSpeed)
            {
                m_Animation.CrossFade(m_WalkAnimation.name);
            }
            else
            {
                m_Animation.CrossFade(m_RunAnimation.name);
            }
        }
        else
        {
            m_Animation.CrossFade(m_IdleAnimation.name);
        }

        m_CollisionFlags = m_Ctl.Move(v3_movement);
        if ((m_vMoveDirection != Vector3.zero) && (!m_bAiming))
        {
            transform.rotation = Quaternion.LookRotation(m_vMoveDirection);
        }
    }