ãUnity9ãUNETã§ãããã¯ã¼ã¯è¶ãã«å¾ã(Rotation)ãåæããããUNET2ã
Unity5.1.1f1 Personal(2015å¹´7æ)
前回の続きã§ãã
ä»åã¯ãªãã¸ã§ã¯ãã®å¾ã(Rotation)ãããã¬ã¤ã¤ã¼éã§åæãã¦ããã¾ãã
UNET Part 2 - Rotation Syncing - YouTube
ãç®æ¨ããªã³ã©ã¤ã³ã§å¾ã(Rotation)ãåæããã
â Menuã·ã¼ã³è¨å®
ã¾ãã¯Mainã·ã¼ã³ã«ä½æããNetworkManagerãMenuã·ã¼ã³ã¸ç§»ãã¾ãã
Mainã·ã¼ã³ã®NetworkManagerãã³ãã¼
Menuã·ã¼ã³ã¸ç§»åãNetworkManagerããã¼ã¹ã
Offlineã«Menuã·ã¼ã³ãOnlineã«Mainã·ã¼ã³ãæå®
ã³ãã¼ãå®äºãããMainã·ã¼ã³ã¸æ»ããNetworkManagerãåé¤ãã¾ãã
以ä¸ã§Menuã·ã¼ã³ããMainã·ã¼ã³ã¸é·ç§»ããæã«NetworkManagerãå¼ãç¶ãè¨å®ãå®äºãã¾ããã
â¡ã©ã¤ãã®è¨å®
ç¶ãã¦ãä»ã®ç¶æ ã ã¨ã©ã¤ãé¢ä¿ã§ãã°ããããããã®ã§ãã©ã¤ãã®è¨å®ããã¦ããã¾ãã(ã©ã®ãããªãã°ãªã®ãã¯åããã¾ããã§ããã)
Mainã·ã¼ã³ã«ã¦Window > Lightingãé¸æãã¦ä¸ããã
Windows > Lighting
ç¶ãã¦Lightingãã¥ã¼ã®Lightmapsãé¸æããAutoã®ãã§ãã¯ãå¤ããBuildãã¿ã³ãæ¼ãã¾ãã
Buildãã¿ã³ãã¯ãªãã¯ï¼
ããã§Mainã·ã¼ã³ã®Projectãã¥ã¼ã«LightMapãã¼ã¿ä½æããã¾ãã
ã¨åæã«ããã°ãæ²»ã£ãããã§ãã
LightMapãã¼ã¿ä½æ
â¢å¾ã(Rotation)ãåæããã
ããããæ¬é¡ã§ãã
ã¾ãã¯Playerãã¬ãããHierarchyãã¥ã¼ã«ä¸æ¦æ»ã
ãã©ãã°ï¼ããããï¼
FIrstPersonCharacterã¯ãã¬ã¤ã¤ã¼ãæ©ãã¦ããæããåºãããã«ã移åä¸Position.xã¨yãå¾®å¦ã«å¤åãããç»é¢ãæºããã¦ãã¾ãã
CubeãFIrstPersonCharacterã®åãªãã¸ã§ã¯ãã«ãã¦ãCubeã«ã®ä½ç½®ã«å¾®å¦ãªå¤åãä»ãå ãã¾ãããã
Cubeãåãªãã¸ã§ã¯ãã«ãã
ç¶ãã¦FirstPersonCharacterã®Positionã微調æ´ãã¾ãã
ããã¾ã§å®äºããããRotationãåæãããã¹ã¯ãªããPlayer_SyncRotationãä½æãã¦Playerã«åãä»ãã¦ä¸ããã
using UnityEngine; using UnityEngine.Networking; using System.Collections; public class Player_SyncRotation : NetworkBehaviour { //SyncVar: ãã¹ããµã¼ãã¼ããã¯ã©ã¤ã¢ã³ãã¸éããã //ãã¬ã¤ã¤ã¼ã®è§åº¦ [SyncVar] private Quaternion syncPlayerRotation; //FirstPersonCharacterã®ã«ã¡ã©ã®è§åº¦ [SyncVar] private Quaternion syncCamRotation; [SerializeField] private Transform playerTransform; [SerializeField] private Transform camTransform; [SerializeField] private float lerpRate = 15; // Use this for initialization void Start () { } // Update is called once per frame void FixedUpdate () { //ã¯ã©ã¤ã¢ã³ãå´ã®Playerã®è§åº¦ãåå¾ TransmitRotations(); //ç¾å¨è§åº¦ã¨åå¾ããè§åº¦ãè£éãã LerpRotations(); } //è§åº¦ãè£éããã¡ã½ãã void LerpRotations () { //èªãã¬ã¤ã¤ã¼ä»¥å¤ã®Playerã®æ if (!isLocalPlayer){ //ãã¬ã¤ã¤ã¼ã®è§åº¦ã¨ã«ã¡ã©ã®è§åº¦ãè£é playerTransform.rotation = Quaternion.Lerp (playerTransform.rotation, syncPlayerRotation, Time.deltaTime * lerpRate); camTransform.rotation = Quaternion.Lerp (camTransform.rotation, syncCamRotation, Time.deltaTime * lerpRate); } } //ã¯ã©ã¤ã¢ã³ããããã¹ãã¸éããã [Command] void CmdProvideRotationsToServer (Quaternion playerRot, Quaternion camRot) { syncPlayerRotation = playerRot; syncCamRotation = camRot; } //ã¯ã©ã¤ã¢ã³ãå´ã ããå®è¡ã§ããã¡ã½ãã [Client] void TransmitRotations () { if (isLocalPlayer) { CmdProvideRotationsToServer(playerTransform.rotation, camTransform.rotation); } } }
Player_SyncRotation.cs
ã¾ãã¯SerializeFieldã®å¤æ°ï¼ã¤ããInspectorãã¥ã¼ããæå®ãã¾ãã
ãã©ãã°ï¼ããããï¼
ã¹ã¯ãªããã§ã¯Playerã®å¾ãã¨ãFIrstPersonCharacterã®ã«ã¡ã©ã®å¾ãã®åæãã¨ã£ã¦ãã¾ãã
ååã®Player_SyncPositionã¨ãã£ã¦ãããã¨ã¯åãã§ãã
FixedUpdateããTransmitRotationã¡ã½ãããå¼ã¶
ã¯ã©ã¤ã¢ã³ããµã¼ãã¼ã使ã£ã¦ããæããªãã¸ã§ã¯ããèªãã¬ã¤ã¤ã¼ã§ããå ´åãCmdProvideRotationsToServerã¡ã½ãããå¼ã³åºã
CmdProvideRotationsToServerã¡ã½ããã«ã¦ãèªãã¬ã¤ã¤ã¼ã¨ã«ã¡ã©ã®è§åº¦ãSyncVarã®å¤æ°ã«ä¿åãã
å
¨ãã¬ã¤ã¤ã¼åã®SyncVarå¤æ°ãããã¹ãããã¯ã©ã¤ã¢ã³ãã¸éä¿¡ãã
LerpRotationã¡ã½ããã«ã¦ãä»ãã¬ã¤ã¤ã¼ã®ç¾å¨ã®å¾ãã¨SyncVarå¤æ°ã®å¾ãã¨ã®ä¸éå¤ãè£éãã
éãã¨ããã°[Client]ã¨[ClientCallback]ã®éãã ãã§ãããä»ã¯ã¾ã ããåããã¾ããã
ãã®ãã¡åãã£ã¦ãããè£è¶³ãã¦ããããã¨æãã¾ãã
ã¨ããããããã¬ã¤ã¤ã¼ã®è§åº¦ã¨ã«ã¡ã©ã®è§åº¦ãè£éãããªãããã«åãããã¨ãã§ããããã«ãªãã¾ããã
ãªãããã«åæãã¨ãã¦ãã¾ã(ç»åãããããã)
ã¾ãã¾ãåç»ã®éä¸ã§ããé·ããªã£ã¦ããã®ã§ãä»åã¯ããã¾ã§ã§ãã
ãããã¨ããããã¾ããã
ãUnity9ãUNETã§ãã«ããã¬ã¤ã¤ã¼ãªãªã³ã©ã¤ã³ã²ã¼ã éçºãUNET1ã
ãUnity9ãUNETã§ãã¬ã¤ã¤ã¼ã®åããè£éãããªããããªåããå®ç¾ãããUNET1-2ã
ãUnity9ãUNETã§ãããã¯ã¼ã¯è¶ãã«å¾ã(Rotation)ãåæããããUNET2ã
ãUnity9ãUNETã§ãªã³ã©ã¤ã³éå§æã®ãã¬ã¤ã¤ã¼çæä½ç½®ãå¤æ´ãããUNET2-2ã
ãUnity9ãUNETã®ãããã¯ã¼ã¯ãã©ãã£ãã¯ã軽æ¸ããå¹çåãããUNET3ã
ãUnity9ãUNETã®latency(é
延æé)ãæ¹åãããUNET4ã
ãUnity9ãUNETã®latency(é
延æé)ã表示ãã¦ãã¡ãã£ã¨ã ãæ¹åãããUNET4-2ã
ãUnity9ãUNETã®SyncVarã®hookã®ä½¿ç¨ä¾ã¨ãåæ代ã®åææ¹æ³ãUNET5ã
ãUnity9ãUNETã使ã£ã¦RotationãåæããããUNET6ã
ãUnity9ãUNETã§åãã¬ã¤ã¤ã¼ã«PlayerIDãè¨å®ãããUNET7ã
ãUnity9ãUNETã§æµãã¬ã¤ã¤ã¼ã«ãã¡ã¼ã¸ãä¸ããï¼ãUNET8ã
ãUnity9ãUNETã§HPãç»é¢ã«è¡¨ç¤ºããPlayerã¸ãã¡ã¼ã¸ãä¸ãããUNET9ã
ãUnity9ãUNETã§HPã0以ä¸ã«ãªã£ãæãPlayerãç ´å£ããï¼ãUNET10ã
ãUnity9ãUNETã§æ»ãã Playerãçãè¿ãããï¼ãUNET11ã
ãUnity9ãUNETã§ã¾ã³ãAIãåºç¾ãããï¼ãUNET12ã
ãUnity9ãUNETã§ã¾ã³ãçææã«ã¦ãã¼ã¯ãªIDãä»ããï¼ãUNET13ã
ãUnity9ãUNETã§ã¾ã³ããæã¤ï¼ãUNET14ã
ãUnity9ãUNETã§ã¾ã³ãã«æ»æãããï¼ãUNET15ã
ãUnity9ãUNETã§ã¾ã³ãã®åããã¹ã ã¼ãºã«ã·ã³ã¯ããããï¼ãUNET16ã
ãUnity9ãUNETã§ã¾ã³ãçºçå°ç¹ãå¢ãããUNET17ã
ãUnity9ãUNETã§çºçãããã°ãåãé¤ããUNET18ã
ãUnity9ãUnity MultiPlayerã使ã£ã¦ãããã¯ã¼ã¯è¶ãã«ãããã¡ã¤ãã³ã°ï¼ãUNET19ã
ãUnity9ãGUIãæ¹åãã¦ãNetwork Managerãè¦ãããããï¼ãUNET20ã
ãUnity9ã表示ããGUI(Network Manager)ãæ©è½ãããï¼ãUNET20-2ã
ãUnity9ãUNETã§Animationãåæãããï¼ãUNET21ã