- Home /
For my multiplayer FPS, the 3rd person character is not moving
I'm currently working on a multiplayer fps which is still in early stages of development. One issue is that the 3rd person character won't move with the player and just stays at the origin. I have the first person controller and 3rd person controller parented to an empty gameobject with the gun and arms parented to the first person controller. When I parent the 3rd person character to the first person controller it follows the controller, but doesn't show up because in my script the first person view isn't viewable by other players.
Here is my only script that is associated with the 3rd person player
public class PlayerManager : MonoBehaviour
{
public Transform firstPerson;
public Transform thirdPerson;
public WeaponManager firstPersonCont;
public Player userPlayer;
public Vector3 currentPosition;
public Quaternion currentRotation;
public GameObject ragDoll;
public Player lastShotBy;
public string lastShotByName;
void Start ()
{
userPlayer = NetworkManager.GetPlayer(networkView.owner);
userPlayer.manager = this;
firstPerson.gameObject.SetActive(false);
thirdPerson.gameObject.SetActive(false);
DontDestroyOnLoad(gameObject);
}
void Update()
{
}
[RPC]
public void FindHitter(string name)
{
lastShotBy = NetworkManager.GetPlayer(name);
lastShotByName = name;
}
[RPC]
public void GetKill()
{
RankManager.instance.EXP += 100;
}
[RPC]
void Server_TakeDamage(int damage)
{
networkView.RPC("Client_TakeDamage", RPCMode.Server, damage);
}
[RPC]
void Client_TakeDamage(int damage)
{
userPlayer.playerHealth -= damage;
Debug.Log(userPlayer.playerHealth);
if(userPlayer.playerHealth <= 0)
{
networkView.RPC("Die", RPCMode.All);
userPlayer.isAlive = false;
userPlayer.playerHealth = 0;
Instantiate(ragDoll, thirdPerson.position, thirdPerson.rotation);
}
}
[RPC]
void Spawn()
{
userPlayer.playerHealth = 100;
userPlayer.isAlive = true;
if (networkView.isMine)
{
firstPerson.gameObject.SetActive(true);;
thirdPerson.gameObject.SetActive(false);
}
else
{
firstPerson.gameObject.SetActive(false);
thirdPerson.gameObject.SetActive(true);
}
}
[RPC]
void Die()
{
userPlayer.isAlive = false;
firstPerson.gameObject.SetActive(false);
thirdPerson.gameObject.SetActive(false);
lastShotBy.manager.networkView.RPC("GetKill", lastShotBy.onlinePlayer);
}
void OnSerializeNetworkView(BitStream stream, NetworkMessageInfo info)
{
if(stream.isWriting)
{
currentPosition = firstPerson.position;
currentRotation = firstPerson.rotation;
stream.Serialize(ref currentPosition);
stream.Serialize(ref currentRotation);
char anim = (char)GetComponent<NetworkAnims>().currentAnimation;
stream.Serialize(ref anim);
}
else
{
stream.Serialize(ref currentPosition);
stream.Serialize(ref currentRotation);
thirdPerson.position = currentPosition;
thirdPerson.rotation = currentRotation;
char anim = (char)0;
stream.Serialize(ref anim);
GetComponent<NetworkAnims>().currentAnimation = (Animations)anim;
}
}
}
Your answer
Follow this Question
Related Questions
yield WaitForSeconds c# 4 Answers
[Closed]multiplayer camera script 2 Answers
Calling the Experts! Problems with Networking: Client/Server Architecture 1 Answer
Machine Learning for FPS game 1 Answer
FPS MultiPlayer 2 Answers