Sync problems
hello to anybody reading this.
i have 2 problems with syncing.
player model sync animation and weapon sync.
so let me explain.
some how the player model sync animation stopped working (when i fixed it) but the legs (cause i use the same animation but its only for local player to see their legs) still works. (with this i mean, multiplayer model animation doesnt sync, only idle animation plays and thats all, mean while singleplayer model animation still doesnt work)
and the weapon sync, it just only has 1 gun model but tho it should change, when i have a rpg it should show that i have the rpg but it doesnt)
heres my scripts
i have 2 problems with syncing.
player model sync animation and weapon sync.
so let me explain.
some how the player model sync animation stopped working (when i fixed it) but the legs (cause i use the same animation but its only for local player to see their legs) still works. (with this i mean, multiplayer model animation doesnt sync, only idle animation plays and thats all, mean while singleplayer model animation still doesnt work)
and the weapon sync, it just only has 1 gun model but tho it should change, when i have a rpg it should show that i have the rpg but it doesnt)
heres my scripts
using UnityEngine; using System.Collections; using System.Collections.Generic; public class CharacterAnimation : MonoBehaviour { [HideInInspector] public string animationSyncHelper; [HideInInspector] public string animationForHands; [HideInInspector] public string activeWeapon; [HideInInspector] public string animationType; public WeaponManager weaponManager; public enum Action { Stand, Crouch, Prone } Action action; [System.Serializable] public class animations { public AnimationClip jumpPose; public AnimationClip stayIdle; public AnimationClip crouchIdle; public AnimationClip proneIdle; public AnimationClip walkFront; public AnimationClip runFront; public AnimationClip crouchFront; public AnimationClip proneFront; public AnimationClip pistolIdle; public AnimationClip knifeIdle; public AnimationClip gunIdle; } public animations Animations; public List<WeaponScript> twoHandedWeapons = new List<WeaponScript>(); public List<WeaponScript> pistols = new List<WeaponScript>(); public List<WeaponScript> knivesNades = new List<WeaponScript>(); FPScontroller fpsController; void Start() { fpsController = transform.root.GetComponent<FPScontroller>(); configureAnimations(); if (weaponManager) { ThirdPersonWeaponControl(); } } void LateUpdate() { if (weaponManager.SelectedWeapon) { activeWeapon = weaponManager.SelectedWeapon.weaponName; } if (!fpsController.crouch && !fpsController.prone) { action = Action.Stand; } else { if (fpsController.crouch && !fpsController.prone) { action = Action.Crouch; } if (!fpsController.crouch && fpsController.prone) { action = Action.Prone; } if (fpsController.crouch && fpsController.prone) { action = Action.Crouch; } } if (action == Action.Stand) { if (fpsController.grounded) { if (fpsController.Walking) { if (!fpsController.Running) { animationType = "Walking"; if (Input.GetKey(KeyCode.W)) { GetComponent<Animation>().CrossFade(Animations.walkFront.name, 0.2f); animationSyncHelper = Animations.walkFront.name; } else if (Input.GetKey(KeyCode.A) && !Input.GetKey(KeyCode.S)) { GetComponent<Animation>().CrossFade(Animations.walkFront.name, 0.2f); animationSyncHelper = Animations.walkFront.name; } else if (Input.GetKey(KeyCode.D) && !Input.GetKey(KeyCode.S)) { GetComponent<Animation>().CrossFade(Animations.walkFront.name, 0.2f); animationSyncHelper = Animations.walkFront.name; } else if (Input.GetKey(KeyCode.S)) { GetComponent<Animation>().CrossFade(Animations.walkFront.name, 0.2f); animationSyncHelper = Animations.walkFront.name; } } else { animationType = "Running"; if (Input.GetKey(KeyCode.W)) { GetComponent<Animation>().CrossFade(Animations.runFront.name, 0.2f); animationSyncHelper = Animations.runFront.name; } } } else { GetComponent<Animation>().CrossFade(Animations.stayIdle.name, 0.2f); animationSyncHelper = Animations.stayIdle.name; } } else { GetComponent<Animation>().CrossFade(Animations.jumpPose.name, 0.2f); animationSyncHelper = Animations.jumpPose.name; } } if (action == Action.Crouch) { animationType = "Crouch"; if (fpsController.Walking) { if (Input.GetKey(KeyCode.W)) { GetComponent<Animation>().CrossFade(Animations.crouchFront.name, 0.2f); animationSyncHelper = Animations.crouchFront.name; } else if (Input.GetKey(KeyCode.A) && !Input.GetKey(KeyCode.S)) { GetComponent<Animation>().CrossFade(Animations.crouchFront.name, 0.2f); animationSyncHelper = Animations.crouchFront.name; } else if (Input.GetKey(KeyCode.D) && !Input.GetKey(KeyCode.S)) { GetComponent<Animation>().CrossFade(Animations.crouchFront.name, 0.2f); animationSyncHelper = Animations.crouchFront.name; } else if (Input.GetKey(KeyCode.S)) { GetComponent<Animation>().CrossFade(Animations.crouchFront.name, 0.2f); animationSyncHelper = Animations.crouchFront.name; } } else { GetComponent<Animation>().CrossFade(Animations.crouchIdle.name, 0.2f); animationSyncHelper = Animations.crouchIdle.name; } } if (action == Action.Prone) { animationType = "Prone"; if (fpsController.Walking) { if (Input.GetKey(KeyCode.W)) { GetComponent<Animation>().CrossFade(Animations.proneFront.name, 0.2f); animationSyncHelper = Animations.proneFront.name; } else if (Input.GetKey(KeyCode.A) && !Input.GetKey(KeyCode.S)) { GetComponent<Animation>().CrossFade(Animations.proneFront.name, 0.2f); animationSyncHelper = Animations.proneFront.name; } else if (Input.GetKey(KeyCode.D) && !Input.GetKey(KeyCode.S)) { GetComponent<Animation>().CrossFade(Animations.proneFront.name, 0.2f); animationSyncHelper = Animations.proneFront.name; } else if (Input.GetKey(KeyCode.S)) { GetComponent<Animation>().CrossFade(Animations.proneFront.name, 0.2f); animationSyncHelper = Animations.proneFront.name; } } else { GetComponent<Animation>().CrossFade(Animations.proneIdle.name, 0.2f); animationSyncHelper = Animations.proneIdle.name; } } ThirdPersonWeaponControl(); } void ThirdPersonWeaponControl() { if (action != Action.Prone) { if (twoHandedWeapons.Contains(weaponManager.SelectedWeapon)) { animationForHands = Animations.gunIdle.name; } else if (pistols.Contains(weaponManager.SelectedWeapon)) { animationForHands = Animations.pistolIdle.name; } else if (knivesNades.Contains(weaponManager.SelectedWeapon)) { animationForHands = Animations.knifeIdle.name; } } else { animationForHands = "Null"; } } void configureAnimations() { if (Animations.stayIdle) { GetComponent<Animation>()[Animations.stayIdle.name].wrapMode = WrapMode.Loop; } if (Animations.crouchIdle) { GetComponent<Animation>()[Animations.crouchIdle.name].wrapMode = WrapMode.Loop; } if (Animations.proneIdle) { GetComponent<Animation>()[Animations.proneIdle.name].wrapMode = WrapMode.Loop; } if (Animations.walkFront) { GetComponent<Animation>()[Animations.walkFront.name].wrapMode = WrapMode.Loop; } if (Animations.runFront) { GetComponent<Animation>()[Animations.runFront.name].wrapMode = WrapMode.Loop; } if (Animations.crouchFront) { GetComponent<Animation>()[Animations.crouchFront.name].wrapMode = WrapMode.Loop; } if (Animations.proneFront) { GetComponent<Animation>()[Animations.proneFront.name].wrapMode = WrapMode.Loop; } } }
-1
Comments
-
using System.Collections; using UnityEngine; [RequireComponent(typeof(AudioSource))] public class WeaponSync : MonoBehaviour { public WeaponScript firstPersonWeapon; public Transform firePoint; public GameObject bullet; public Renderer muzzleFlash; public Rigidbody projectile; public AudioClip fireAudio; private void Start() { if ((bool)muzzleFlash) { muzzleFlash.GetComponent<Renderer>().enabled = false; } GetComponent<AudioSource>().playOnAwake = false; GetComponent<AudioSource>().volume = 0.5f; if (GetComponent<AudioSource>().maxDistance > 10f) { GetComponent<AudioSource>().maxDistance = 75f; GetComponent<AudioSource>().minDistance = 0f; } if (!firstPersonWeapon) { return; } if (firstPersonWeapon.GunType == WeaponScript.gunType.MACHINE_GUN) { if ((bool)firstPersonWeapon.machineGun.bullet) { bullet = firstPersonWeapon.machineGun.bullet.gameObject; } if ((bool)firstPersonWeapon.machineGun.fireSound) { fireAudio = firstPersonWeapon.machineGun.fireSound; } } if (firstPersonWeapon.GunType == WeaponScript.gunType.SHOTGUN) { if ((bool)firstPersonWeapon.ShotGun.bullet) { bullet = firstPersonWeapon.ShotGun.bullet.gameObject; } if ((bool)firstPersonWeapon.ShotGun.fireSound) { fireAudio = firstPersonWeapon.ShotGun.fireSound; } } if (firstPersonWeapon.GunType == WeaponScript.gunType.GRENADE_LAUNCHER) { if ((bool)firstPersonWeapon.grenadeLauncher.projectile) { projectile = firstPersonWeapon.grenadeLauncher.projectile; } if ((bool)firstPersonWeapon.grenadeLauncher.fireSound) { fireAudio = firstPersonWeapon.grenadeLauncher.fireSound; } } if (firstPersonWeapon.GunType == WeaponScript.gunType.KNIFE && (bool)firstPersonWeapon.knife.fireSound) { fireAudio = firstPersonWeapon.knife.fireSound; } } private void syncMachineGun(float errorAngle) { StopAllCoroutines(); StartCoroutine(machineGunShot(errorAngle)); } private IEnumerator machineGunShot(float errorAngle) { Quaternion oldRotation = firePoint.rotation; firePoint.rotation = Quaternion.Euler(UnityEngine.Random.insideUnitSphere * errorAngle) * firePoint.rotation; GameObject instantiatedBullet = UnityEngine.Object.Instantiate(bullet, firePoint.position, firePoint.rotation); instantiatedBullet.GetComponent<Bullet>().doDamage = false; firePoint.rotation = oldRotation; GetComponent<AudioSource>().clip = fireAudio; GetComponent<AudioSource>().Play(); if ((bool)muzzleFlash) { muzzleFlash.GetComponent<Renderer>().enabled = true; yield return new WaitForSeconds(0.04f); muzzleFlash.GetComponent<Renderer>().enabled = false; } } private void syncShotGun(float fractions) { StopAllCoroutines(); StartCoroutine(shotGunShot(fractions)); } private IEnumerator shotGunShot(float fractions) { for (int i = 0; i < (int)fractions; i++) { Quaternion rotation = firePoint.rotation; firePoint.rotation = Quaternion.Euler(UnityEngine.Random.insideUnitSphere * 3f) * firePoint.rotation; GameObject gameObject = UnityEngine.Object.Instantiate(bullet, firePoint.position, firePoint.rotation); gameObject.GetComponent<Bullet>().doDamage = false; firePoint.rotation = rotation; } GetComponent<AudioSource>().clip = fireAudio; GetComponent<AudioSource>().Play(); if ((bool)muzzleFlash) { muzzleFlash.GetComponent<Renderer>().enabled = true; yield return new WaitForSeconds(0.04f); muzzleFlash.GetComponent<Renderer>().enabled = false; } } private void syncGrenadeLauncher(float initialSpeed) { grenadeLauncherShot(initialSpeed); } private void grenadeLauncherShot(float initialSpeed) { Rigidbody rigidbody = UnityEngine.Object.Instantiate(projectile, firePoint.position, firePoint.rotation); rigidbody.GetComponent<Projectile>().isRemote = true; rigidbody.AddForce(rigidbody.transform.forward * initialSpeed * 50f); Physics.IgnoreCollision(rigidbody.GetComponent<Collider>(), base.transform.root.GetComponent<Collider>()); Collider[] componentsInChildren = base.transform.root.GetComponentsInChildren<Collider>(); foreach (Collider collider in componentsInChildren) { Physics.IgnoreCollision(rigidbody.GetComponent<Collider>(), collider); } GetComponent<AudioSource>().clip = fireAudio; GetComponent<AudioSource>().Play(); } private void syncKnife(float temp) { knifeOneHit(); } private void knifeOneHit() { GetComponent<AudioSource>().clip = fireAudio; GetComponent<AudioSource>().Play(); } }
0 -
using UnityEngine; public class WeaponSync_Catcher : MonoBehaviour { private Transform playerRoot; private WeaponScript weapScript; private PlayerNetworkController pnc; private void Awake() { weapScript = base.gameObject.GetComponent<WeaponScript>(); playerRoot = base.transform.root; pnc = playerRoot.GetComponent<PlayerNetworkController>(); } public void Fire() { if (weapScript.GunType == WeaponScript.gunType.MACHINE_GUN) { pnc.syncMachineGun(weapScript.errorAngle); } if (weapScript.GunType == WeaponScript.gunType.SHOTGUN) { pnc.syncShotGun(weapScript.ShotGun.fractions); } if (weapScript.GunType == WeaponScript.gunType.GRENADE_LAUNCHER) { pnc.syncGrenadeLauncher(weapScript.grenadeLauncher.initialSpeed); } if (weapScript.GunType == WeaponScript.gunType.KNIFE) { pnc.syncKnife(); } } }
-1 -
using UnityEngine; using System.Collections; using System.Collections.Generic; public class PlayerNetworkController : Photon.MonoBehaviour { [HideInInspector] public string playerName; public Transform lookTarget; CharacterController cc; RoomMultiplayerMenu rmm; GameObject currentActiveWeapon; public Transform thirdPersonWeapons; public Transform shoulderR; public Transform shoulderL; public CharacterAnimation characterAnimation; [System.Serializable] public class AnimationSpeed{ public float walkSpeed = 1; public float runSpeed = 1; public float crouchSpeed = 1; public float proneSpeed = 1; } public AnimationSpeed animationSpeed; List<string> mixedAnimations = new List<string>(); string MovementAnimation; string currentBlendedAnimation; string currentWeaponName; private string currentAnimation = ""; private string blendedAnimation = ""; private string prevWeap = ""; public DrawPlayerName drawPlayerName; public PlayerDamage playerDamage; public HeadLookController headLookController; public List<GameObject> remoteObjectsToDeactivate; public List<MonoBehaviour> remoteScriptsToDeactivate; public List<GameObject> localObjectsToDeactivate; public List<MonoBehaviour> localScriptsToDeactivate; [HideInInspector] public bool playerIsOurs; void Awake () { if(!photonView.isMine){ for(int i = 0; i<remoteObjectsToDeactivate.Count;i++){ remoteObjectsToDeactivate[i].SetActive(false); } for(int a = 0; a<remoteScriptsToDeactivate.Count;a++){ Destroy(remoteScriptsToDeactivate[a]); } gameObject.tag = "Remote"; if(lookTarget.gameObject.activeSelf == false){ lookTarget.gameObject.SetActive(true); } }else{ for(int b = 0; b<localObjectsToDeactivate.Count;b++){ localObjectsToDeactivate[b].SetActive(false); } for(int c = 0; c<localScriptsToDeactivate.Count;c++){ Destroy(localScriptsToDeactivate[c]); } Destroy(headLookController); } rmm = GameObject.FindWithTag("Network").GetComponent<RoomMultiplayerMenu>(); } void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info){ if (stream.isWriting){ stream.SendNext(transform.position); stream.SendNext(transform.rotation); stream.SendNext(gameObject.name); stream.SendNext(lookTarget.position); stream.SendNext(lookTarget.rotation); stream.SendNext((string)PhotonNetwork.player.customProperties["TeamName"]); stream.SendNext(characterAnimation.animationSyncHelper); stream.SendNext(characterAnimation.animationForHands); stream.SendNext(characterAnimation.activeWeapon); stream.SendNext(characterAnimation.animationType); }else{ correctPlayerPos = (Vector3)stream.ReceiveNext(); correctPlayerRot = (Quaternion)stream.ReceiveNext(); PlayerName = (string)stream.ReceiveNext(); lookTargetPos = (Vector3)stream.ReceiveNext(); lookTargetRot = (Quaternion)stream.ReceiveNext(); playerTeam = (string)stream.ReceiveNext(); currentAnimation = (string)stream.ReceiveNext(); blendedAnimation = (string)stream.ReceiveNext(); currentWeaponName = (string)stream.ReceiveNext(); animType = (string)stream.ReceiveNext(); } } private Vector3 correctPlayerPos = new Vector3(0, -100, 0); private Quaternion correctPlayerRot = Quaternion.identity; private string PlayerName = ""; private Vector3 lookTargetPos = Vector3.zero; private Quaternion lookTargetRot = Quaternion.identity; private string playerTeam = ""; private string animType = ""; void Update(){ playerIsOurs = photonView.isMine; if (!photonView.isMine){ transform.position = Vector3.Lerp(transform.position, correctPlayerPos, Time.deltaTime * 8); transform.rotation = Quaternion.Lerp(transform.rotation, correctPlayerRot, Time.deltaTime * 8); lookTarget.position = Vector3.Lerp(lookTarget.position, lookTargetPos, Time.deltaTime * 8); lookTarget.rotation = lookTargetRot; if(gameObject.name != PlayerName){ gameObject.name = PlayerName; } if(rmm.gameMode == "TDM"){ if(playerTeam == (string)PhotonNetwork.player.customProperties["TeamName"]){ playerDamage.disableDamage = true; drawPlayerName.enabled = true; }else{ playerDamage.disableDamage = false; drawPlayerName.enabled = false; } }else{ drawPlayerName.enabled = false; } if(MovementAnimation != currentAnimation){ MovementAnimation = currentAnimation; if(animType == "Walking"){ headLookController.GetComponent<Animation>()[MovementAnimation].speed = animationSpeed.walkSpeed; } if(animType == "Running"){ headLookController.GetComponent<Animation>()[MovementAnimation].speed = animationSpeed.runSpeed; } if(animType == "Crouch"){ headLookController.GetComponent<Animation>()[MovementAnimation].speed = animationSpeed.crouchSpeed; } if(animType == "Prone"){ headLookController.GetComponent<Animation>()[MovementAnimation].speed = animationSpeed.proneSpeed; } if(headLookController.GetComponent<Animation>()[MovementAnimation] != null){ headLookController.GetComponent<Animation>()[MovementAnimation].layer = 1; headLookController.GetComponent<Animation>()[MovementAnimation].wrapMode = WrapMode.Loop; } } if(headLookController.GetComponent<Animation>()[MovementAnimation] != null){ headLookController.GetComponent<Animation>().CrossFade(MovementAnimation); } if(currentBlendedAnimation != blendedAnimation){ currentBlendedAnimation = blendedAnimation; if(!mixedAnimations.Contains(currentBlendedAnimation) && currentBlendedAnimation != "Null" && headLookController.GetComponent<Animation>()[currentBlendedAnimation] != null){ headLookController.GetComponent<Animation>()[currentBlendedAnimation].layer = 4; headLookController.GetComponent<Animation>()[currentBlendedAnimation].wrapMode = WrapMode.Loop; headLookController.GetComponent<Animation>()[currentBlendedAnimation].AddMixingTransform(shoulderR); headLookController.GetComponent<Animation>()[currentBlendedAnimation].AddMixingTransform(shoulderL); mixedAnimations.Add (currentBlendedAnimation); } } if(currentBlendedAnimation != "Null" && headLookController.GetComponent<Animation>()[currentBlendedAnimation] != null){ headLookController.GetComponent<Animation>().Play(currentBlendedAnimation); } if(prevWeap != currentWeaponName){ for(int i = 0; i < thirdPersonWeapons.childCount; i++){ if(thirdPersonWeapons.GetChild(i).name != currentWeaponName){ thirdPersonWeapons.GetChild(i).gameObject.SetActive(false); }else{ thirdPersonWeapons.GetChild(i).gameObject.SetActive(true); currentActiveWeapon = thirdPersonWeapons.GetChild(i).gameObject; } } prevWeap = currentWeaponName; } } } public void ReDeactivatePlayerObjects(){ if(photonView.isMine){ for(int b = 0; b<localObjectsToDeactivate.Count;b++){ localObjectsToDeactivate[b].SetActive(false); } for(int c = 0; c<localScriptsToDeactivate.Count;c++){ Destroy(localScriptsToDeactivate[c]); } } } public void syncMachineGun(float errorAngle){ photonView.RPC ("SyncWeaponsRPC", PhotonTargets.Others, "syncMachineGun", errorAngle); } public void syncShotGun(int fractions){ photonView.RPC ("SyncWeaponsRPC", PhotonTargets.Others, "syncShotGun", (float)fractions); } public void syncGrenadeLauncher(float initialSpeed){ photonView.RPC ("SyncWeaponsRPC", PhotonTargets.Others, "syncGrenadeLauncher", initialSpeed); } public void syncKnife(){ photonView.RPC ("SyncWeaponsRPC", PhotonTargets.Others, "syncKnife", 0.0f); } [PunRPC] void SyncWeaponsRPC(string functionName, float Value){ if(currentActiveWeapon){ currentActiveWeapon.SendMessage(functionName, Value, SendMessageOptions.DontRequireReceiver); } } }
-1 -
if i added more than 2 scripts, its cause they are togheter, they both need each other0
-
weapon sync needs player network, same with character animation0
-
Maybe you should find/hire experienced programmer who will help you with this project?-1
-
OneManArmy wrote: »Maybe you should find/hire experienced programmer who will help you with this project?
i already have someone helping me with programming but photon just wont work anymore0 -
OneManArmy wrote: »Maybe you should find/hire experienced programmer who will help you with this project?
Also we tried collabing on unity but it costs money since my project is more than 1GB0 -
OneManArmy wrote: »Maybe you should find/hire experienced programmer who will help you with this project?
Back then it actually used to work, like i said in the message it only worked just for a week, i have never touched that script or weapon sync or even upgraded my unity or photon, just did it by it self.0 -
all i wanna do is just to get weapon sync and players animation syncing working again0
-
Federico123 wrote: »all i wanna do is just to get weapon sync and players animation syncing working again0
-
Hello everyone, I have fixed this, how did i fix it? well me being the smart smart i havent put the stuff needed for the character animation, player network and weapon sync
1 -
Glad you fixed it.
This is, by the way, something we would not be able to find in a hundred years with just the code. You need to debug this kind of stuff on your end by all means.
If you bump your own problem threads multiple times a day, everyone is actually less inclined to even read it...0