using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PushableObject : MonoBehaviour
{

    public float gravity = 60;
    Controller2D controller;
    Vector3 velocity;

    void Start()
    {
        controller = GetComponent<Controller2D>();
    }

    void Update()
    {
        velocity += Vector3.down * gravity * Time.deltaTime;
        var moveAmount = controller.Move(velocity * Time.deltaTime, false);
        if (controller.collisions.below)
        {
            velocity = Vector3.zero;
        }
        if ((controller.collisions.left && moveAmount.x < 0) || (controller.collisions.right && moveAmount.x > 0))
        {
            velocity.x = 0;
        }

    }

    public Vector2 Push(Vector2 amount, Transform pusher)
    {
        if (pusher.tag.Equals("Pushable"))
            return controller.Move(amount * 0.2f, false);

        return controller.Move(amount, false);
    }
}
