UPDATED: I have been trying to implement a Orbital Camera of sorts in a engine I am currently doing in Unity3D, the issue being I can't seem to do the correct rotation no matter what.
This is what it is needed:
Rotate on Y and X axis via the mouse, but the Y and X axis are not Vector.up or Vector.right they are given by the current Slope of the Target I am orbiting around.
I don't get how I can make it idependent of the character rotation, but at the same time dependent
This sorta works, but some loops have issues, check the video below for a taste of whats wrong
var forward = Vector3.forward; //Vector3.Cross(ViewTarget.transform.up, transform.right); //Apply the rotation var rot = Quaternion.AngleAxis(CurrentHorizontalLook, ViewTarget.transform.up); var rot2 = Quaternion.AngleAxis(CurrentVerticalLook, transform.right) ; Debug.DrawRay(ViewTarget.transform.position, Vector3.right * 5, Color.yellow, 0, false); Debug.DrawRay(ViewTarget.transform.position, ViewTarget.transform.up * 5, Color.blue, 0, false); var offset = forward * 5; transform.rotation = rot * rot2; transform.position = ViewTarget.transform.position + EyeHeight + transform.rotation*-offset; transform.LookAt(ViewTarget.transform.position, ViewTarget.transform.up);
EDIT : Maybe this image will help.
Black is the Up Vector, Red is the rotation on X Axis, Green is rotation on Y Axis. The trick here is it being idependent of the right and forward of the Target object , only the Up vector used to align the camera.
Edit: I have "something" that is somewhat related to what I want, but still missing one thing.
I got the camera to rotate correctly on the target Y axis, but it doesn't align to the ground plane at all.
Convention : Y = UP Z = Forward X = Right
var rot = Quaternion.AngleAxis(CurrentHorizontalLook, ViewTarget.transform.up); transform.rotation = rot ; var rot2 = Quaternion.AngleAxis(CurrentVerticalLook, transform.right) ; transform.rotation = rot * rot2; var offset = forward * 5;
This is what I have , the issue now being that if the character is on a 90 degree wall the camera should be moving around the character on the same plane as the wall, but in my case it looks in a top down manner. If instead of WorldForward I used TargetForward it moves in the correct plane, but then when the character changes direction the camera shifts too.
I think a better explanation of what I want is this : I want the camera to rotate on the X,Z Plane of the character, and I want to be able to tilt it up or down in the Y,Z Plane. If you check the video I posted when Sonic goes in loop I want the camera to do sorta the same thing.