Rigidbody AddForce doesnt work in Photon Unity

Viewed 595

When it try to add a Force to my Player it moves and then gets teleported back. Do i need to use a RPC ?

New Code:

void OnTriggerEnter(Collider other)
{
    if (other.gameObject.CompareTag("Weapon"))
    {

        rb.AddForce(Vector3.back * knockbackStrength, ForceMode.Impulse);


    }
}
1 Answers

I would personally write this as:

public Rigidbody rb;
public float knockbackStrength;

void OnTriggerEnter(Collider collision)
{
    if (collision.collider.tag == "Player")
    {

        rb.AddForce(collision.position, ForceMode.Impulse);


    }
}

As I haven't seen the rest of your code, I've added in the variables, and please could you clarify what the 5 and 0 parameters in the rb.AddForce() function is trying to achieve? I've taken them out because I never have them in. but it all depends on the desired outcome. Try it this way anyway, it might work.

Related