コード例 #1
0
    void Awake()
    {
        collisionData = new List <SuperCollision>();

        TemporaryLayerIndex = LayerMask.NameToLayer(TemporaryLayer);

        ignoredColliders     = new List <Collider>();
        ignoredColliderStack = new List <IgnoredCollider>();

        currentlyClampedTo = null;

        fixedDeltaTime = 1.0f / fixedUpdatesPerSecond;

        heightScale = 1.0f;

        if (ownCollider)
        {
            IgnoreCollider(ownCollider);
        }
        else
        {
            ownCollider = GetComponent <CapsuleCollider>();
        }

        foreach (var sphere in spheres)
        {
            if (sphere.isFeet)
            {
                feet = sphere;
            }

            if (sphere.isHead)
            {
                head = sphere;
            }
        }

        if (feet == null)
        {
            Debug.LogError("[SuperCharacterController] Feet not found on controller");
        }

        if (head == null)
        {
            Debug.LogError("[SuperCharacterController] Head not found on controller");
        }

        if (defaultCollisionType == null)
        {
            defaultCollisionType = new GameObject("DefaultSuperCollisionType", typeof(SuperCollisionType)).GetComponent <SuperCollisionType>();
        }

        currentGround = new SuperGround(Walkable, this, triggerInteraction);

        manualUpdateOnly = false;

        gameObject.SendMessage("SuperStart", SendMessageOptions.DontRequireReceiver);
    }
    void Awake()
    {
        collisionData = new List<SuperCollision>();

        TemporaryLayerIndex = LayerMask.NameToLayer(TemporaryLayer);

        ignoredColliders = new List<Collider>();
        ignoredColliderStack = new List<IgnoredCollider>();

        currentlyClampedTo = null;

        fixedDeltaTime = 1.0f / fixedUpdatesPerSecond;

        heightScale = 1.0f;

        if (ownCollider)
            IgnoreCollider(ownCollider);

        foreach (var sphere in spheres)
        {
            if (sphere.isFeet)
                feet = sphere;

            if (sphere.isHead)
                head = sphere;
        }

        if (feet == null)
            Debug.LogError("[SuperCharacterController] Feet not found on controller");

        if (head == null)
            Debug.LogError("[SuperCharacterController] Head not found on controller");

        if (defaultCollisionType == null)
            defaultCollisionType = new GameObject("DefaultSuperCollisionType", typeof(SuperCollisionType)).GetComponent<SuperCollisionType>();

        currentGround = new SuperGround(Walkable, this);

        manualUpdateOnly = false;

        gameObject.SendMessage("SuperStart", SendMessageOptions.DontRequireReceiver);
    }
コード例 #3
0
    void SingleUpdate()
    {
        if (currentGround == null)
        {
            currentGround = new SuperGround(Walkable, this, triggerInteraction);
        }

        // Check if we are clamped to an object implicity or explicity
        bool      isClamping = clamping || currentlyClampedTo != null;
        Transform clampedTo  = currentlyClampedTo != null ? currentlyClampedTo : currentGround.transform;

        if (clampToMovingGround && isClamping && clampedTo != null && clampedTo.position - lastGroundPosition != Vector3.zero)
        {
            transform.position += clampedTo.position - lastGroundPosition;
        }

        initialPosition = transform.position;

        ProbeGround(1);

        //transform.position += debugMove * deltaTime;

        gameObject.SendMessage("SuperUpdate", SendMessageOptions.DontRequireReceiver);

        if (collisionData != null)
        {
            collisionData.Clear();
        }
        RecursivePushback(0, MaxPushbackIterations);

        ProbeGround(2);

        if (slopeLimiting)
        {
            SlopeLimit();
        }

        ProbeGround(3);

        if (clamping)
        {
            ClampToGround();
        }

        isClamping = clamping || currentlyClampedTo != null;
        clampedTo  = currentlyClampedTo != null ? currentlyClampedTo : currentGround.transform;

        if (isClamping)
        {
            lastGroundPosition = clampedTo.position;
        }

        if (debugGrounding)
        {
            currentGround.DebugGround(true, true, true, true, true);
        }

        if (AfterSingleUpdate != null)
        {
            AfterSingleUpdate();
        }
    }