Hello to everyone!
I am working on a top down 2D game and I need your help with pushing an object.
My player, which is a monster, should push a box when it collides with it. I tried several solutions, only one works for me but it works not smooth.
Here is my code for the box:
private void OnTriggerEnter2D(Collider2D other)
{
if (other.tag == "Player")
{
this.direction = other.GetComponent<Monster> ().direction;
transform.Translate (other.GetComponent<Monster>().direction * other.GetComponent<Monster>().speed * Time.deltaTime);
}
}
The player has the Monster.cs script on it an has a given direction, saved in direction.
What am I doing wrong? Or is there a better solution to push an object in a top down 2D game?
Thanks in advance!