Search Unity

Parent Player Rotate With Child Camera

Discussion in 'Scripting' started by Kiesco91, May 24, 2020.

  1. Kiesco91

    Kiesco91

    Joined:
    Aug 20, 2018
    Posts:
    80
    Hello,

    I'm having an issue with getting my parent player object not rotating with my child camera. I am using the RB FPS Controller from standard assets and I have a FixedTouch Panel to rotate my camera and that works absolutely fine so don't want to mess with that.

    I also have a simple joystick set up for my player and the issue is when I start the game everything works great. forwards, backwards, left and right and I can look around but then if I look around or spin my camera 180 and try to move, the players rotation doesn't follow so up becomes down and right becomes left etc. I know I have nothing in my script to warrant this but I don't know how to as the camera is a child object. I have tried setting the camera as the parent and the RB FPS as a child but then my camera doesn't work properly and the character doesn't move at all.

    my basic movement script:

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class PlayerMovement : MonoBehaviour
    6. {
    7.  
    8.     public CharacterController controllerPlayer;
    9.     public float speed = 10f;
    10.  
    11.     // Start is called before the first frame update
    12.     void Start()
    13.     {
    14.         controllerPlayer = GetComponent<CharacterController>();
    15.     }
    16.  
    17.     // Update is called once per frame
    18.     void Update()
    19.     {
    20.         Vector3 mov = new Vector3(SimpleInput.GetAxis("Horizontal") * speed, 0, SimpleInput.GetAxis("Vertical") * speed);
    21.  
    22.         controllerPlayer.Move(mov * Time.deltaTime);
    23.     }
    24. }

    Thanks In Advance!
     
  2. davidnibi

    davidnibi

    Joined:
    Dec 19, 2012
    Posts:
    426
    What happens if you directly alter this objects transforms and not character controller?
     
  3. Kiesco91

    Kiesco91

    Joined:
    Aug 20, 2018
    Posts:
    80
    Hello!

    Sorry, I'm not 100% what you mean. As in manually adjust the transform? So if I 180 my camera in play mode and then in the inspector, 180 my character, the movement then becomes normalized again.

    Thanks