- Home /
Camera 360 degree rotation without flipping
Hey there, i created a camera which follows the player who is moving around a sphere. The problem I am having is that whenever the player reaches the "north" or "south" pole of the sphere the camera flips by 180 degress...
After searching through the internet, i assume that this has something to do with the allignment to worldspace or whatever... I don't really get it neither do I have a solution but hopefully anyone get help me solve this issue.
using UnityEngine;
using System.Collections;
public class smoothFollow : MonoBehaviour
{
GameObject player;
GameObject orbit;
public float distance;
void Start()
{
//Find Player
player = GameObject.FindWithTag("Player");
//Find Orbit
orbit = GameObject.FindWithTag("Orbit");
}
void FixedUpdate()
{
//Get Transforms
Transform playerPos = player.transform;
Transform orbitPos = orbit.transform;
//Get Camera rotation
Quaternion rotation = Quaternion.LookRotation(playerPos.position);
// Set camera rotation
transform.rotation = rotation;
//Get target Position
Vector3 targetPos = orbitPos.position - playerPos.position;
//Vector3 camPos = rotation * new Vector3(0, 0, distance) + targetPos;
targetPos = playerPos.position - targetPos.normalized * distance;
//Set Position
transform.position = Vector3.Slerp(transform.position, targetPos, 10 * Time.deltaTime);
transform.LookAt(orbitPos, transform.up);
}
}
Hey thanks for the answers, tried it out, moving ovr the north7 southpole basically works without the camera flipping however the camera now flips when I move to the left or right.
Any ideas ?
Your answer
Follow this Question
Related Questions
camera movements very slow, why!? :) 2 Answers
How can you make a FPS controller camera "fly"? 1 Answer
Mouse Camera Control 0 Answers
Teleporting a camera to a camera 1 Answer
Camera 2D Movement android unity 1 Answer