- Home /
Player Model Floating after Spawn
Hi, I've been following this tutorial.
https://www.youtube.com/watch?v=yxt6Nbxk8Hw
I'm trying to do the create fps multiplayer but now that I have set everything up. My character is now floating in the air. Before I added the Model to my player controller my character was spawning on the ground, I think but just as a capsul. This is what it looks like now. after I have added the model to my player controller
http://imgur.com/1YOLXN9 playmode http://imgur.com/JIw0aIY nonplaymode1 http://imgur.com/Jhf6tym nonplaymode2
Here is the Network Manager script using UnityEngine; using System.Collections;
public class NetworkManager : MonoBehaviour {
public GameObject standbyCamera;
SpawnSpot[] spawnSpots;
// Use this for initialization
void Start () {
spawnSpots = GameObject.FindObjectsOfType<SpawnSpot> ();
Connect ();
}
void Connect() {
PhotonNetwork.ConnectUsingSettings ( "MultiFPS v001" );
}
void OnGUI() {
GUILayout.Label (PhotonNetwork.connectionStateDetailed.ToString ());
}
void OnJoinedLobby() {
Debug.Log ("OnJoinedLobby");
PhotonNetwork.JoinRandomRoom ();
}
void OnPhotonRandomJoinFailed() {
Debug.Log ("OnPhotonRandomJoinFailed");
PhotonNetwork.CreateRoom (null);
}
void OnJoinedRoom() {
Debug.Log ("OnJoinedRoom");
SpawnMyPlayer ();
}
void SpawnMyPlayer() {
if (spawnSpots == null) {
Debug.LogError ("WTF");
return;
}
SpawnSpot mySpawnSpot = spawnSpots [Random.Range (0, spawnSpots.Length)];
GameObject myPlayerGO = (GameObject)PhotonNetwork.Instantiate ("PlayerController", mySpawnSpot.transform.position, mySpawnSpot.transform.rotation, 0);
standbyCamera.SetActive (false);
myPlayerGO.GetComponent<FPSInputController>().enabled = true;
myPlayerGO.GetComponent<MouseLook>().enabled = true;
myPlayerGO.GetComponent<CharacterMotor>().enabled = true;
myPlayerGO.transform.FindChild ("Main Camera").gameObject.SetActive (true);
}
}
Here is NetworkCharacter Script
using UnityEngine; using System.Collections;
public class NetworkCharacter : Photon.MonoBehaviour {
Vector3 realPosition = Vector3.zero;
Quaternion realRotation = Quaternion.identity;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if (photonView.isMine) {
// Do nothing -- the character motor/input/etc... is moving us
}
else {
transform.position = Vector3.Lerp (transform.position, realPosition, 0.1f);
transform.rotation = Quaternion.Lerp (transform.rotation, realRotation, 0.1f);
}
}
public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info) {
if(stream.isWriting) {
// This is OUR player. We need to send our actual position to the network.
stream.SendNext (transform.position);
stream.SendNext (transform.rotation);
}
else {
// This is someone else's player. We need to receive their position (as of a few
// millisecond ago, and update our version of that player.
realPosition = (Vector3)stream.ReceiveNext();
realRotation = (Quaternion)stream.ReceiveNext();
}
}
}
Here is spawnspots script
using UnityEngine; using System.Collections;
public class SpawnSpot : MonoBehaviour {
public int team=0;
}
The white blox are my spawnspots
please if you can help me I've been stuck here a while.. Thank you very much. Also, if you need any more information please let me know.
Richie
Answer by theANMATOR2b · Oct 07, 2014 at 03:29 PM
Hey Richie I know this is a simple (non coder) answer and you've probably already tried this but it looks like your character mesh should be roughly centered in the middle of the character capsule collider instead of at the top of it. http://docs.unity3d.com/Manual/class-CharacterController.html
Thank you, I was changing the location of the graphics within the collider.. I was forgetting to hit apply after.
Thanks, Richie
Answer by conceptfac · May 09, 2019 at 04:45 AM
Here is happening the same problem, but offline mode all is normal