Multiplayer: How to make players push each other.
Hello,
I started a new project to get the hang of multiplayer. I have followed this tutorial to get started: https://unity3d.com/es/learn/tutorials/topics/multiplayer-networking
Its all good and dandy, but I want to make players able to collide and push each other. By simply adding the rigidbody2d to the networktransform, doesn't do the trick, as its like players are.... relunctant to being pushed.
Is there any way to make players pushable as regular singleplayer rigidbodies?
Thanks,
Add a rigidbody to enemy with a box collider.$$anonymous$$ake sure the box collider of both player and enemy is not triggered.
Players collide. The problem is that each player has authority over his own rigidbody, so they can't be pushed by external forces.
Try this :
public float pushbackForce;
void pushback(Transform pushedObject)
{
Vector2 pushdirection = new Vector2(0, pushedObject.position.y - transform.position.y).normalized;
pushdirection *= pushbackForce;
Rigidbody2D pushRb = pushedObject.gameObject.GetComponent<Rigidbody2D>();
pushRb.velocity = Vector2.zero;
pushRb.AddForce(pushdirection, Force$$anonymous$$ode2D.Impulse);
}
}
Your answer
Follow this Question
Related Questions
Rigidbody follow player and maintain all physical properties 1 Answer
my bullet keeps firing up 0 Answers
Problem with force movement when calling from another scripts 0 Answers
AddTorque turning not rotating opposite direction. 2 Answers
Unable to AddForce on a game object containing a RigidBody2D and a HingeJoint2D? 1 Answer