Quantcast
Channel: Recent Discussions — Photon Engine
Viewing all articles
Browse latest Browse all 15755

Syncing animations that are caused by colliders

$
0
0
I am currently stuck on how to implement this:
Player 1 casts Skill A, which travels along and collides with Player 2. Player 2 is affected by the skill and loses health, has an animation that shows that it got hit, and knocks Player 2 back.

So far I am able to do all this, but it only shows in the local instance. I have synced up the player movement and animations using the PhotonViewAnimator, and PhotonView, so the players are able to see each other walk and jump around. Although when a player casts a skills only the avatar animator are sync up, the particle effect of the skill when it is travelling, and the interaction with the other player (as detailed above) are not synced.

I tried to fix this by using OnPhotonSerializeView, but it didn't work below is what I currently have:

For the OnTriggerEnter method of the skill

void OnTriggerEnter(Collider collider) {
GameObject characterObject = collider.gameObject;
PlayerCharacter characterComponent = characterObject.GetComponent<PlayerCharacter>();
if (characterComponent)
{
this.collidedCharacter = characterObject;
characterObject.GetComponent<Health>().DecreaseHealth(changeInLife);
this.ApplyEffects(characterComponent);
characterComponent.TakeImpact();
}
}


Note that here PlayerCharacter is the class that handles all the movement and animations of the Player, it is also the class that implemented IPunObservable for OnPhotonSerializeView. Below are the part of the code for PlayerCharacter that are relevant:

public void TakeImpact()
{
m_Animator.SetBool("Impact 0", true);
print ("Taken impact");
}
public void OnPhotonSerializeView (PhotonStream stream, PhotonMessageInfo info)
{

if (stream.isWriting)
{
// We own this player: send the others our data
stream.SendNext(m_Animator.GetBool("Impact 0"));
print (m_Animator.GetBool ("Impact 0"));
}else{
// Network player, receive data
m_Animator.SetBool("Impact 0", (bool)stream.ReceiveNext());
}
}


So basically (from a high level), the skill collides with a GameObject, and if that GameObject is a PlayerCharacter then the skill will invoke the TakeImpact() method of the PlayerCharacter which will set the Animator of the player that the skill collided with to true. Although this is only shown on the local network, and is not synced across the network, and this is where I am currently stuck.

I am thinking that I should make the skill have PhotonView components so that it can be synced up, but no matter what I try it doesn't work. I feel that the fix is a very trivial fix but I can't seem to get my head around it would anyone care to help?


Viewing all articles
Browse latest Browse all 15755

Trending Articles