First Person Camera not being child of the character/ Set child's rotation to global rotation

Hey there,

I’m relatively new to Unity and I am trying to create a FPS with physics similar to Mario Galaxy where you can hop from planetoid to planetoid and such things. I am now facing a problem with my camera when changing the planet. In my scene, every planetoid has a trigger around them and when a rigidbody touches it, it is attracted by the planetoid. This is true for projectiles as well as the player. Now my problem is, when I am changing the planet as player, the player’s gets rotated so that his feet land on the ground first. My camera is a child of the player and when the player gets into a new orbit, the camera’s x-rotation stays the same, so the camera is “jumping” from one rotation to another. This really affects the orientation and because of that I want the camera to still look into the same direction when changing the orbit.

I already tried to unchild the camera from the player but then I am not able to make the camera’s rotation be the player’s rotation.

Has anyone of you a solution for this? I would prefer the camera to stay a child of the player but maybe anyone of you has a better solution for this.

Thanks in advance :slight_smile:

You could try lerping the cameras rotation to smoothly transition from one rotation to another using the Quaternion.Lerp function. I know this is not the full answer, but it will help with the “jumping” from one rotation to another. Here is a tutorial on lerping, if you are new to unity. The tutorial explains how to do it with position, but its the same basic idea for rotation as well.

@lurxy try this. it’s untested in this form but should work.

using UnityEngine;
using System;
using System.Collections;
/*
--------------------------------------------------------------------------------------------
this is a bare bones version of my cam rig in my game, it is only the core 
functions for following and rotation, it is very easy to extend into nearly anything.
--------------------------------------------------------------------------------------------
*/
public class camrigsimple : MonoBehaviour {
public Transform target; // set this or it won't follow anything and will spam your console until you do so
[SerializeField]
private float smoothTime = 3; // how fast the camera responds to movement, higher = slower
[SerializeField]
private float rotationSmooth = 2; // how fast the camera responds to rotation, higher = slower
[SerializeField]
private float distance = 3;
[SerializeField]
private float height = 1.3f;
private Vector3 velocity = Vector3.zero;

void Update(){ // use FixedUpdate if following a rigidbody
if (target){
Vector3 targetPosition = target.TransformPoint(new Vector3(0, height, -distance));
transform.position = Vector3.SmoothDamp(transform.position, targetPosition, ref velocity, smoothTime * Time.deltaTime);	
transform.rotation = Quaternion.Slerp(transform.rotation, target.rotation, rotationSmooth * Time.deltaTime);
}else {Debug.Log("no target!");}
}
}