Move() public méthode

Attempt to move the character to current position + velocity. Any colliders in our way will cause velocity to be modified ex: wall -> stop. slope -> modifiy velocity.\n NOTE collisions.velocity has the real velocity applied
public Move ( Vector3 velocity, float delta ) : Vector3
velocity Vector3 Amount to be moved (velocity * delta)
delta float Time since last update
Résultat Vector3
Exemple #1
0
        /// <summary>
        /// Managed update called by UpdateManager
        /// Transform Input into platformer magic :)
        /// </summary>
        public virtual void PlatformerUpdate(float delta)
        {
            frozen -= delta;
            int             prio = 0;
            int             tmp;
            CharacterAction action = null;

            if (frozen < 0)
            {
                foreach (var i in actions)
                {
                    tmp = i.WantsToUpdate(delta);
                    if (tmp < 0)
                    {
                        i.PerformAction(Time.fixedDeltaTime);
                    }
                    else if (prio < tmp)
                    {
                        prio   = tmp;
                        action = i;
                    }
                }
            }

            // reset / defaults
            pc2d.disableWorldCollisions = false;
            PostUpdateActions a = PostUpdateActions.WORLD_COLLISIONS | PostUpdateActions.APPLY_GRAVITY;

            if (action != null)
            {
                if (lastAction != action)
                {
                    action.GainControl(delta);
                }

                action.PerformAction(Time.fixedDeltaTime);
                a = action.GetPostUpdateActions();
            }

            if (Utils.biton((int)a, (int)PostUpdateActions.APPLY_GRAVITY))
            {
                // TODO REVIEW x/y gravity...
                velocity.y += pc2d.gravity.y * delta;
            }

            if (!Utils.biton((int)a, (int)PostUpdateActions.WORLD_COLLISIONS))
            {
                pc2d.disableWorldCollisions = true;
            }

            if (Mathf.Abs(velocity.x) < minVelocity)
            {
                velocity.x = 0.0f;
            }

            if (Mathf.Abs(velocity.y) < minVelocity)
            {
                velocity.y = 0.0f;
            }

            if (onBeforeMove != null)
            {
                onBeforeMove(this, delta);
            }

            pc2d.Move((velocity + worldVelocity) * delta, delta);

            if (onAfterMove != null)
            {
                onAfterMove(this, delta);
            }


            // this is meant to fix jump and falling hit something unexpected
            if (pc2d.collisions.above || pc2d.collisions.below)
            {
                velocity.y = 0;
            }

            if (pc2d.collisions.below)
            {
                fallingCD.Reset();
                groundCD.Reset();
                SolfEnterState(States.OnGround);
            }
            else
            {
                groundCD.Increment();
                // give some margin
                if (groundCD.Ready())
                {
                    SolfExitState(States.OnGround);
                }

                // falling but not wallsliding
                if (velocity.y < 0 &&
                    !IsOnState(States.WallSliding) &&
                    !IsOnState(States.Liquid) &&
                    !IsOnState(States.Rope))
                {
                    fallingCD.Increment();
                    if (fallingCD.Ready())
                    {
                        SolfEnterState(States.Falling);
                    }
                }
            }

            if (lastAction != null && lastAction != action)
            {
                lastAction.LoseControl(delta);
            }

            lastAction = action;
        }
Exemple #2
0
        /// <summary>
        /// Managed update called by UpdateManager
        /// Transform Input into platformer magic :)
        /// </summary>
        public virtual void PlatformerUpdate(float delta)
        {
            // before anything try to find if there is a ladder below
            // it's neccesary for ActionLadder&ActionCrounch
            RaycastHit2D hit = pc2d.DoFeetRay(
                pc2d.skinWidth * 2,
                Configuration.instance.laddersMask
                );

            if (hit)
            {
                ladderBottom = hit.collider.gameObject.GetComponent <Ladder>();
                if (ladderBottom == null)
                {
                    Debug.LogWarning("Object with ladder mask but no Ladder Behaviour found", hit.collider.gameObject);
                }
            }
            else
            {
                ladderBottom = null;
            }

            //
            frozen -= delta;
            int             prio = 0;
            int             tmp;
            CharacterAction action = null;

            if (frozen < 0)
            {
                foreach (var i in actions)
                {
                    tmp = i.WantsToUpdate(delta);
                    if (tmp < 0)
                    {
                        i.PerformAction(Time.fixedDeltaTime);
                    }
                    else if (prio < tmp)
                    {
                        prio   = tmp;
                        action = i;
                    }
                }
            }

            // reset / defaults
            pc2d.disableWorldCollisions = false;
            PostUpdateActions a = PostUpdateActions.WORLD_COLLISIONS | PostUpdateActions.APPLY_GRAVITY;

            if (action != null)
            {
                if (lastAction != action)
                {
                    action.GainControl(delta);
                }

                action.PerformAction(Time.fixedDeltaTime);
                a = action.GetPostUpdateActions();
            }

            if (Utils.biton((int)a, (int)PostUpdateActions.APPLY_GRAVITY))
            {
                // TODO REVIEW x/y gravity...
                velocity.y += pc2d.gravity.y * delta;
            }

            if (!Utils.biton((int)a, (int)PostUpdateActions.WORLD_COLLISIONS))
            {
                pc2d.disableWorldCollisions = true;
            }

            if (Mathf.Abs(velocity.x) < minVelocity)
            {
                velocity.x = 0.0f;
            }

            if (Mathf.Abs(velocity.y) < minVelocity)
            {
                velocity.y = 0.0f;
            }

            if (onBeforeMove != null)
            {
                onBeforeMove(this, delta);
            }

            movedLastFrame = pc2d.Move((velocity + worldVelocity) * delta, delta);

            if (onAfterMove != null)
            {
                onAfterMove(this, delta);
            }


            // this is meant to fix jump and falling hit something unexpected
            if (pc2d.collisions.above || pc2d.collisions.below)
            {
                velocity.y = 0;
            }

            if (pc2d.collisions.below)
            {
                fallingCD.Reset();
                groundCD.Reset();
                EnterStateGraceful(States.OnGround);
            }
            else
            {
                groundCD.Increment();
                // give some margin
                if (groundCD.Ready())
                {
                    ExitStateGraceful(States.OnGround);
                }

                // falling but not wallsliding
                if (velocity.y < 0 &&
                    !IsOnState(States.WallSliding) &&
                    !IsOnState(States.Liquid) &&
                    !IsOnState(States.Rope))
                {
                    fallingCD.Increment();
                    if (fallingCD.Ready())
                    {
                        EnterStateGraceful(States.Falling);
                    }
                }
            }

            if (lastAction != null && lastAction != action)
            {
                lastAction.LoseControl(delta);
            }

            lastAction = action;
        }