Photon Network, addforce

Hello Everyone,

I am trying to make the player push another player away when you hit him.

I tried a lot of different things, just add the force from the attacker to the defender, didn't react at all.

Now the closest i got is this :
[code2=csharp]public bool hitted; //Is the player attacked?
public Vector3 attackerPos; //What is the attackers pos.

void Update (){
if(hitted == true) //if the player is attacked.
{
Debug.Log("AU"); //debug this.
rigidbody.AddForce(attackerPos,ForceMode.Acceleration); // and add the force in the opposite direction of the attacker

hitted = false;
}
}

if(canMelee)
{
body.GetComponent<Animator>().SetBool("Melee", true);
canMelee = false;
Ray ray = new Ray(transform.position + Vector3.up / 4, transform.TransformDirection(Vector3.forward));
Debug.DrawRay(ray.origin, ray.direction, Color.red);
RaycastHit hit;
if (Physics.Raycast(ray, out hit, meleeRange))
{
if(hit.collider.tag == "Player")
{
switch (character)
{
case "Brawler" :
//TODO : zorgen dat de speler het target weg pushed, over het netwerk het signaal sturen dat hij is geraakt.
hit.collider.GetComponent<PlayerScriptMP>().hitted = true;
hit.collider.GetComponent<PlayerScriptMP>().attackerPos = transform.position;
//Vector3 forceVec = -hit.rigidbody.velocity.normalized * 500;
//hit.collider.rigidbody.AddForce(-forceVec,ForceMode.Acceleration);
break;
case "Striker" :
//TODO : zorgen dat het target zijn camera uit en in fade.
Debug.Log("Fade Camera.");
break;
case "Bug" :
hit.collider.GetComponent<PlayerScriptMP>().stunned = true;
stunned = false;
break;
}

canMelee = false;
}
}
}[/code2]
what am i doing wrong? It is working on the attackers screen, but on the defenders screen the player stays on the same position.

thanks in advance

Comments

  • I didn't try your code but this might help:
    Keep in mind that only the owner of a GameObject can send where the object is. If you don't tell this user to push the object, then it won't move, except locally.
    Doing physics in a networked game is quite complex: Anyone (the world's physics) can move any object. Done on multiple clients at the same time with slightly different situations OR in concurrent directions, it is difficult to pick the correct result. If two soccer players kicked the ball in different directions at the same time: Which kick do you actually use? In the real world, the ball would probably skip up or not move at all. But there's lag in the networked simulation.

    I don't have a proper solution and can't make up one right now. My favorite solution would be to change the game design in this case ;)