Photon Impact/repeal effect

Options
Hi @Tobias, im trying to make a 2d game fight multiplayer with photon.

But right now I have specific problems with the impact or repeal effect.
My characters are sync via the position. I have made a video:

Link to the video: https://youtu.be/Hv9egnXZFtM

If you look at the video, there are 2 windows(only you need to look at the left windows).
When my player(YOU) attack with the UpperCut movement to the "mod(no real player)" in the right the impact/repeal is very synchronized (that is because that mod is local). BUT when I attack to the "Player7661" and I made the UpperCut movement the impact/repeal is very desynchronized, I know it's difficult get an perfect sync but I like to get to something closer that I have now.

Right now i have in the Players an OnTriggerEnter2D in charge of the impact/repeal with a function, this is my code:

void Hit (Vector2 velocity, int fromSign) {
string anim = "";
if ((flipped ? -1 : 1) != fromSign) {
//anim = hitBackwardAnim;
anim = animaciones [6];
animacionesNro = 6;
} else {
//anim = hitForwardAnim;
anim = animaciones [6];
animacionesNro = 6;
}

skeletonAnimation.state.SetAnimation (0, anim, false);
skeletonAnimation.state.AddAnimation (0, idleAnim, true, 1.2f);
}

void OnTriggerEnter2D (Collider2D collider) {

if (photonView.isMine) {
var boundingBoxFollower = collider.GetComponent ();
if (boundingBoxFollower != null) {
var attachmentName = boundingBoxFollower.CurrentAttachmentName;

int fromSign = collider.transform.position.x < transform.position.x ? -1 : 1;
switch (attachmentName) {
case "UpperCut":
Hit (new Vector2 (-fromSign * 4, 8), fromSign);
break;
case "Punch":
Hit (new Vector2 (-fromSign * 2, 0), fromSign);
break;
}
}
}
}


Regards!

Comments

  • mrwayne
    mrwayne
    edited August 2015
    Options
    Sorry when I say repeal I mean "REPEL", sorry for my English.
    I attach in this link the code for better view:
    https://gist.github.com/anonymous/954541bde66d82750cfa

    Regards,
  • Tobias
    Options
    The explanation why the repel is delayed is easy: The remote client is always in control of his character. After it got the hit, it detects the trigger and moves accordingly, which takes another moment to reach the origin of the hit.

    If the kicking client can decide that a hit is definitely a hit, you could locally take over control of the hit character temporarily, to move it accordingly (repel).
    The remote player will do the same but later. You can try to catch up a bit of time by playing the animation faster or by skipping a bit of distance.
    In any case, you soon have to re-sync the "local simulation" with the real, incoming data from the other player (who controls the character).

    You could potentially delay input locally by a fixed time. If you send input right away but execute it 100ms later, this gives your messages a bit of a headstart to reach the other player(s).

    I am not an expert either. This is somewhat related and might give you more ideas:
    http://gafferongames.com/networked-physics/snapshots-and-interpolation/
  • mrwayne
    Options
    Hi @Tobias ! thanks you for the reply.
    I get a solution in the local player, what I did was when my player made the UpperCut attack and impact to Player7661(the other player) then I turn off the sync of the transform.position.y for 1.2 seconds of the Player7661 and only I use his transform.position.x in that interval of the 1.2 seconds.

    What you think of my solution? or it is better to do another way?

    Regards,

  • Tobias
    Options
    If the solution looks good in your game, that's perfectly fine. The solution must fit your game, so it's probably good :)