Push player with object

Hi,
i’m working on script that can object push players when it hits them, what should I use to do like this?
Thanks

You can use rigidbodys on players and on the object and let the physics engine of unity to take care the rest or you coud use a collider on the object and add a script that implements OnColiisionEnter event, and inside that event put some code that applies force to the player that its colliding with the object.

3 Likes

Yeah as @Sherlock-jr mentioned,adding rigidbodies is the right choice

1 Like
    void OnCollisionEnter(Collision c)
    {
        float force = 3;
        if (c.gameObject.tag == "Player")
        {
            Vector3 dir = c.contacts[0].point - transform.position;
            dir = -dir.normalized;
            GetComponent<Rigidbody>().AddForce(dir * force);
            Debug.Log("Forced");

        }
    }

Doesn’t work

Solved , Thank you guys