// Update is called once per frame void Update() { // #SHOW45 We adopt position smoother function here. m_positionFollower.FrameMove(Time.deltaTime); var p = new Nettention.Proud.Vector3(); var v = new Nettention.Proud.Vector3(); m_positionFollower.GetFollower(ref p, ref v); transform.position = new UnityEngine.Vector3((float)p.x, (float)p.y, (float)p.z); }
public void RotationPos(UnityEngine.Vector3 position, UnityEngine.Vector3 rotation) { _position = position; _rotation = rotation; var npos = new Nettention.Proud.Vector3(); npos.x = position.x; npos.y = position.y; npos.z = position.z; var nvel = new Nettention.Proud.Vector3(); nvel.x = nvel.y = nvel.z = 0; posFollower.SetTarget(npos, nvel); }
void Update() { posFollower.FrameMove(Time.deltaTime); var pos = new Nettention.Proud.Vector3(); var vel = new Nettention.Proud.Vector3(); posFollower.GetFollower(ref pos, ref vel); _transform.position = new UnityEngine.Vector3((float)pos.x, (float)pos.y, (float)pos.z); if (Quaternion.Angle(_transform.rotation, Quaternion.Euler(_rotation)) > 0.1f) { _transform.rotation = Quaternion.Lerp(_transform.rotation, Quaternion.Euler(_rotation), 20f * Time.deltaTime); } }
public void SetMoveFrameData(UnityEngine.Vector3 position, UnityEngine.Vector3 targetpos, UnityEngine.Vector3 velocity, UnityEngine.Vector3 rotation, float relay) { _targetPosintion = targetpos; _position = position; _rotation = rotation; _velocity = velocity; _relayTime = relay; var npos = new Nettention.Proud.Vector3(); npos.x = position.x; npos.y = position.y; npos.z = position.z; var nvel = new Nettention.Proud.Vector3(); nvel.x = velocity.x; nvel.y = velocity.y; nvel.z = velocity.z; posFollower.SetTarget(npos, nvel); }
// #SHOW23 Client receives the login result. Finished. NOW, TEST IT! private void InitRMI() { m_stub.NotifyLoginSuccess = (HostID remote, RmiContext rmiContext) => { m_state = MyState.Connected; //#SHOW30 call to the server! // join the world! m_proxy.JoinGameScene(HostID.HostID_Server, RmiContext.ReliableSend, m_localPlayer.transform.position.x, m_localPlayer.transform.position.y, m_localPlayer.transform.position.z, m_localPlayer.GetComponent <PlayControl>().carAngle); // show 30 ends here return(true); }; m_stub.NotifyLoginFailed = (HostID remote, RmiContext rmiContext, System.String reason) => { Debug.Log(reason); m_disconnectNow = true; return(true); }; //#SHOW35 On cient, let the other player appear on Unity scene. FINISHED. TEST IT! m_stub.Player_Appear = (HostID remote, RmiContext rmiContext, int hostID, System.String userID, float x, float y, float z, float vx, float vy, float vz, float angle) => { if (hostID != (int)m_netClient.GetLocalHostID()) { var rot = Quaternion.AngleAxis(angle, new UnityEngine.Vector3(0, 1, 0)); var remotePlayerCharacter = (GameObject)Instantiate(m_remotePlayerPrefab, new UnityEngine.Vector3(x, y, z), rot); remotePlayerCharacter.name = "RemotePlayer/" + hostID.ToString(); var control = remotePlayerCharacter.GetComponent <RemoteControl>(); var p = new Nettention.Proud.Vector3(); p.x = x; p.y = y; p.z = z; var v = new Nettention.Proud.Vector3(); v.x = vx; v.y = vy; v.z = vz; control.m_positionFollower.SetTarget(p, v); control.m_positionFollower.SetFollower(p, v); } return(true); }; m_stub.Player_Disappear = (Nettention.Proud.HostID remote, Nettention.Proud.RmiContext rmiContext, int hostID) => { var g = GameObject.Find("RemotePlayer/" + hostID.ToString()); if (g != null) { Destroy(g); } return(true); }; // #SHOW42 On client, receive movement message. m_stub.Player_Move = (Nettention.Proud.HostID remote, Nettention.Proud.RmiContext rmiContext, float x, float y, float z, float vx, float vy, float vz, float angle) => { var g = GameObject.Find("RemotePlayer/" + remote.ToString()); if (g != null) { //g.transform.rotation = new UnityEngine.Vector3(x, y, z); //#SHOW46 we don't move GameObject directly here. But we let positionFollower know it. FINISHED. DO IT! var control = g.GetComponent <RemoteControl>(); var p = new Nettention.Proud.Vector3(); p.x = x; p.y = y; p.z = z; var v = new Nettention.Proud.Vector3(); v.x = vx; v.y = vy; v.z = vz; control.m_positionFollower.SetTarget(p, v); var rot = Quaternion.AngleAxis(angle, new UnityEngine.Vector3(0, 1, 0)); g.transform.rotation = rot; } return(true); }; }