Exemplo n.º 1
0
    private Vector3 CheckDistanceAndLimits(Vector3 newpos)
    {
        Vector3 worldMin = gbStage.GetWorldMin();
        Vector3 worldMax = gbStage.GetWorldMax();

        return(new Vector3(
                   Mathf.Clamp(newpos.x, worldMin.x, worldMax.x),
                   Mathf.Clamp(newpos.y, worldMin.y, worldMax.y),
                   Mathf.Clamp(newpos.z, worldMin.z, worldMax.z)
                   ));
    }
Exemplo n.º 2
0
    void MoveUpdate()
    {
        if (!userMain.CursorOverUI() || (currentTool != null && currentTool.isTriggerDown))
        {
            lookTransform.rotation = navigationControls.GetAim();
        }

        float sprintScale = (navigationControls.IsSprinting() ? 2f : 1);

        currentVelocity = navigationControls.GetVelocity() * moveSpeed * sprintScale;
        avatarTransform.Translate(currentVelocity * Time.unscaledDeltaTime);

        Vector3 avPos = avatarTransform.position;

        bool avatarPositionModified = false;

        Vector3 worldMin = gbStage.GetWorldMin();
        Vector3 worldMax = gbStage.GetWorldMax();

        if (avPos.x < worldMin.x || avPos.x > worldMax.x)
        {
            avPos.x = Mathf.Clamp(avPos.x, worldMin.x, worldMax.x);
            avatarPositionModified = true;
        }

        if (avPos.y < worldMin.y || avPos.y > worldMax.y)
        {
            avPos.y = Mathf.Clamp(avPos.y, worldMin.y, worldMax.y);
            avatarPositionModified = true;
        }

        if (avPos.z < worldMin.z || avPos.z > worldMax.z)
        {
            avPos.z = Mathf.Clamp(avPos.z, worldMin.z, worldMax.z);
            avatarPositionModified = true;
        }

        if (avatarPositionModified)
        {
            avatarTransform.position = avPos;
        }
    }