Search Unity

I'm stuck Large Camera issue

Discussion in 'Getting Started' started by Shadowing, Feb 9, 2015.

  1. Shadowing

    Shadowing

    Joined:
    Jan 29, 2015
    Posts:
    1,648
    Been trying to apply multi player to the survival shooter for the sake of learning multi player.
    I got multi player working but I have this camera issue.

    My player prefab looks like this

    CurrentPlayer
    PlayerCamera
    PlayerWrapper

    Gun
    GunBarrelEnd
    Player

    when game loads the Prefab gets cloned into the scene. All that works fine.
    Player Camera uses a camera follow script which uses PlayerWrapper as a target
    And Player Wrapper has Player Movement script attached to it.

    Hope someone can help me I'm frozen atm :p







    Code (csharp):
    1.  
    2.  
    3. public class CameraFollow : MonoBehaviour {
    4.  
    5.    public Transform target;
    6.    public float smoothing = 5f;
    7.  
    8.    Vector3 offset;
    9.  
    10.    void Start(){
    11.       offset = transform.position - target.position;
    12.    }
    13.  
    14.    void FixedUpdate(){
    15.        Vector3 targetCamPos = target.position + offset;
    16.        transform.position = Vector3.Lerp (transform.position, targetCamPos, smoothing *   Time.deltaTime);
    17.  
    18.    }
    19. }
    20.  
    21.  
    22.  



    Code (csharp):
    1.  
    2. public class PlayerMovement : MonoBehaviour
    3. {
    4.  
    5.    public float speed = 6f;
    6.    Vector3 movement;
    7.    Animator anim;
    8.    Rigidbody playerRigidbody;
    9.    int floorMask;
    10.    float camRayLength = 100f;
    11.  
    12.    void Awake(){
    13.        floorMask = LayerMask.GetMask ("Floor");
    14.       anim = GetComponent<Animator> ();
    15.       playerRigidbody = GetComponent<Rigidbody> ();
    16.    }
    17.  
    18.    void FixedUpdate(){
    19.  
    20.       float h = Input.GetAxisRaw ("Horizontal");
    21.       float v = Input.GetAxisRaw ("Vertical");
    22.  
    23.       Move (h,v);
    24.       Turning ();
    25.       Animating (h,v);
    26.   }
    27.  
    28.    void Move (float h, float v){ // move player in direction
    29.  
    30.       movement.Set (h,0f,v);
    31.       movement = movement.normalized * speed * Time.deltaTime;
    32.       playerRigidbody.MovePosition (transform.position + movement);
    33.    }
    34.  
    35.    void Turning(){
    36.  
    37.       Ray camRay = Camera.main.ScreenPointToRay (Input.mousePosition);
    38.       RaycastHit floorHit;
    39.  
    40.       if(Physics.Raycast(camRay, out floorHit, camRayLength, floorMask)){
    41.          Vector3 playertoMouse = floorHit.point - transform.position;
    42.          playertoMouse.y = 0f;
    43.  
    44.          Quaternion newRotation = Quaternion.LookRotation (playertoMouse);
    45.          playerRigidbody.MoveRotation (newRotation);
    46.       }
    47.    }
    48.  
    49.    void Animating (float h, float v){
    50.       bool walking = h != 0f || v != 0f;
    51.       anim.SetBool ("IsWalking", walking);
    52.    }
    53. }
    54.  






    If I leave the prefab in the scene. I can control that player just fine as shown below.
    The guy in the black bar is the clone prefab player


     
    Last edited: Feb 9, 2015
  2. Shadowing

    Shadowing

    Joined:
    Jan 29, 2015
    Posts:
    1,648
    If I stick the PlayerCamera out side the CurrentPlayer game object the issue is fixed but then the player doesn't have a camera.

    So I added PlayerCamera as a prefab also and Instantiate the player and the camera. But because Current player is not in the scene at the time It won't save its target to the player.


    Code (csharp):
    1.  
    2.  
    3. PhotonNetwork.Instantiate ("PlayerCamera",
    4.   spawnPoints[index].position,
    5.   spawnPoints[index].rotation,
    6.   0);
    7.  
    8. PhotonNetwork.Instantiate ("CurrentPlayer",
    9.   spawnPoints[index].position,
    10.   spawnPoints[index].rotation,
    11.   0);
    12.  
    13.  

    That black bar is the blackness of the Background color of the PlayerCamera Cloned. The black bar appears right when the CurrentPlayer Clone is added in


     
    Last edited: Feb 9, 2015
  3. Shadowing

    Shadowing

    Joined:
    Jan 29, 2015
    Posts:
    1,648
    I think im getting close to solving my problem
    I don't know what took me so long to try this idea out but I placed the player inside the Camear and now the camera preview on the scene view shows how it looks when playing the game.

    Then I was kinda messing around with some stuff and I notice the tilt that exists on the camera showing in the picture below. I'm thinking now that the black bar is showing underneath the floor. Since the back half of the camera is going below the floor.







    Then I zoomed way out and this is what I have. The camera is under the floor way out. So working on this now. Just wanted to update the thread on my progress. I might not be understanding this view though

     
    Last edited: Feb 9, 2015
  4. Shadowing

    Shadowing

    Joined:
    Jan 29, 2015
    Posts:
    1,648
    I fixed my issue. Just took a while messing around with the camera. Looking at different views etc..
     
    Aurore likes this.
  5. Aurore

    Aurore

    Director of Real-Time Learning

    Joined:
    Aug 1, 2012
    Posts:
    3,106
    Glad you solved the issue, how did you fix it exactly?
     
  6. Shadowing

    Shadowing

    Joined:
    Jan 29, 2015
    Posts:
    1,648
    The pointer of the camera was in the wrong spot. Not sure what you call it.
    The + at the bottom of the last picture. It wasn't pointed anywhere near the character.
    I was going to say how I fixed it but its a big confusing on how to explain it lol.
    After messing with some different angles I notice that I was able to point the + at the character

    The strange thing is once I moved it. I was unable to move it again lol. Couldn't figure out how I moved it the first time. Then I had other problems with rendering and stuff. Enviroment objects were not being drawn right. Like something was clipping it.

    Then I changed to a side view and was able to see everything more clearly how the camera was projecting down on the floor