- Home /
Moveing my camera
First of sorry for my bad English.
I have been working on a survival first person game for some time now, but camera moves with him and he got a mecanim system on so when he walk or run the camera get vary shaky. I wanted to make a script that made the cam follow him instead, but since the guy gets spawned in buy a script I cant find him using GameObject.Find. Here is My scrips that spawns him
using UnityEngine; using System.Collections;
public class JoinRoom : Photon.MonoBehaviour {
public string ChooseRoomName;
public string JoinRoomName;
//SpawnSpot [] SpawnSpots;
Vector3 SpawnPos;
Quaternion SpawnRot;
bool Joined = false;
// Use this for initialization
void Start () {
SpawnPos = new Vector3(GameObject.Find("SpawnSpot1").transform.position.x, GameObject.Find("SpawnSpot1").transform.position.y ,GameObject.Find("SpawnSpot1").transform.position.z);
SpawnRot = new Quaternion (GameObject.Find("SpawnSpot1").transform.rotation.x, GameObject.Find("SpawnSpot1").transform.rotation.y, GameObject.Find("SpawnSpot1").transform.rotation.z, 0);
Connect ();
}
void Connect () {
PhotonNetwork.ConnectUsingSettings("v1.1");
}
void OnGUI () {
GUILayout.Label ( PhotonNetwork.connectionStateDetailed.ToString());
}
void OnJoinedLobby() {
Debug.Log ("OnJoinedLobby");
PhotonNetwork.JoinRandomRoom ();
}
void OnPhotonRandomJoinFailed() {
Debug.Log ("OnPhotonRandomJoindFailed");
PhotonNetwork.CreateRoom (null);
}
void OnJoinedRoom() {
Debug.Log ("OnJoinedroom");
SpawnMyPlayer ();
}
void SpawnMyPlayer() {
Debug.Log ("Hello");
//SpawnSpot mySpawnSpot = SpawnSpots [Random.Range (0, SpawnSpots.Length)];
GameObject myPlayerGO = (GameObject)PhotonNetwork.Instantiate ("Player1", SpawnPos, SpawnRot, 0);
GameObject myCamGO = (GameObject)PhotonNetwork.Instantiate ("PlayerCam", SpawnPos, SpawnRot, 0);
myPlayerGO.transform.Find ("Man_Arms").gameObject.SetActive (true);
myPlayerGO.transform.Find ("male_Hi").gameObject.SetActive (false);
myPlayerGO.GetComponent<Mouse_Move> ().enabled = true;
myPlayerGO.GetComponent<Movement_Final> ().enabled = true;
myCamGO.transform.Find ("Main Camera").gameObject.SetActive (true);
myCamGO.GetComponent<Mouse_Move> ().enabled = true;
myCamGO.GetComponent<CamMove> ().enabled = true;
JoinRoom.StartCoroutine(CamMove.MoveCam());
}
} `
I don't need to rotate the camera with him just when he moves. Hope that somebody can help me.
Answer by ComeSweetDeath · Sep 05, 2014 at 05:11 PM
Just a guess, I think the problem might be caused by the camera-follow script that you have on the main camera. If the character moves up and down (in y axis) when animated with a run animation, and the camera-follow script goes something like myCamGO.transform.position = myPlayerGO.transform.position, then the camera will also bob up and down along with the animation. So what you could do is go something like
cam.position.x = player.position.x
cam.position.y = Mathf.Lerp(cam.position.y, player.position.x, Time.deltaTime*speed);
cam.position.z = player.position.x
You might also want to try lerping the x and z as well just to see how things look.
Your answer
Follow this Question
Related Questions
How to make object move and rotate 1 Answer
enable scripts/ components on other gameobjects for a different gameobject? 1 Answer
How to destroy a gameobject on collision 2 Answers
How to destroy a specific gameobject on collision. 1 Answer
The name 'Joystick' does not denote a valid type ('not found') 2 Answers