Esempio n. 1
0
        protected virtual void Update()
        {
            /// 重力加速度
            if (ActiveGravity)
            {
                velocity.y += gravity * CupheadTime.Delta[timeLayer];
            }

            if (MoveByDirectionInput)
            {
                float targetVelocityX = directionalInput.x * StatCollection.GetStatValue(GlobalSymbol.RUN_SPEED);

                velocity.x = Mathf.MoveTowards(velocity.x, targetVelocityX,
                                               isGrounded ? StatCollection.GetStatValue(GlobalSymbol.ACCELERATION_TIME_GROUND) : StatCollection.GetStatValue(GlobalSymbol.ACCELERATION_TIME_AIR));
            }

            if (!_activeControl)
            {
                velocity.x = 0;
            }

            /// 平台碰撞
            //if (controller.collisions.above || controller.collisions.below)
            //    velocity.y = 0;

            controller.Move(velocity * CupheadTime.Delta[timeLayer]);

            /// 平台碰撞
            if (controller.collisionState.above && velocity.y > 0f || controller.collisionState.below && velocity.y < 0f)
            {
                velocity.y = 0.0f;
            }
            if (controller.collisionState.left && velocity.x < 0f || controller.collisionState.right && velocity.x > 0f)
            {
                velocity.x = 0.0f;
            }
        }
Esempio n. 2
0
        protected virtual void Update()
        {
            if (isImmovable /*|| _collider == null*/)
            {
                velocity = Vector2.zero;
                return;
            }

            if (shouldUseGravity)
            {
                velocity += gravity * gravityScale * CupheadTime.Delta[timeLayer];
            }

            _controller.Move(velocity * CupheadTime.Delta[timeLayer]);

            //CollisionResult collisionResult;
            //// fetch anything that we might collide with at our new position
            //var neighbors = Physics.boxcastBroadphaseExcludingSelf( _collider, _collider.collidesWithLayers );
            //foreach( var neighbor in neighbors )
            //{
            //	// if the neighbor collider is of the same entity, ignore it
            //	if( neighbor.entity == gameObject )
            //	{
            //		continue;
            //	}

            //	_collider.ClosestPointOnBounds

            //	if( _collider.collidesWith( neighbor, out collisionResult ) )
            //	{
            //		// if the neighbor has an ArcadeRigidbody we handle full collision response. If not, we calculate things based on the
            //		// neighbor being immovable.
            //		var neighborRigidbody = neighbor.entity.getComponent<ArcadeRigidbody>();
            //		if( neighborRigidbody != null )
            //		{
            //			processOverlap( neighborRigidbody, ref collisionResult.minimumTranslationVector );
            //			processCollision( neighborRigidbody, ref collisionResult.minimumTranslationVector );
            //		}
            //		else
            //		{
            //			// neighbor has no ArcadeRigidbody so we assume its immovable and only move ourself
            //			transform.position -= collisionResult.minimumTranslationVector;
            //			var relativeVelocity = velocity;
            //			calculateResponseVelocity( ref relativeVelocity, ref collisionResult.minimumTranslationVector, out relativeVelocity );
            //			velocity += relativeVelocity;
            //		}
            //	}
            //}
        }