コード例 #1
0
    private void FixedUpdate()
    {
        if (raycastController.collisions.above || raycastController.collisions.below)
        {
            velocity -= Vector3.Dot(gravity.normalized, velocity) * gravity.normalized;
        }

        //Apply gravity
        velocity += gravity * Time.deltaTime;

        //Apply horizontal velocity with smoothing
        Vector3 verticalVelocity          = gravity.normalized * Vector3.Dot(gravity.normalized, velocity);
        Vector3 currentHorizontalVelocity = velocity - verticalVelocity;

        velocity = Vector3.SmoothDamp(currentHorizontalVelocity, inputVelocity, ref velocitySmoothStorage, horizontalVelocitySmoothing, maxSpeed) + verticalVelocity;

        raycastController.ApplyCollisions(ref velocity, gravity);
        transform.Translate(velocity, Space.World);
        velocity = gravity.normalized * Vector3.Dot(gravity.normalized, velocity); //Maintain falling velocity
    }