- Home /
Space Camera Issue.
How to get this clamped input on the local axis, so when I rotate in space(where there is no up or down) it works properly. What happens is that angleF rotates the player along the z axis so when that happens the input and camera still thinks there is up and down so input is made opposite... need that to be stopped!!
if(controlable){
angleH += Mathf.Clamp(Input.GetAxis("Mouse X"), -1, 1) * horizontalAimingSpeed * Time.deltaTime;
angleV += Mathf.Clamp(Input.GetAxis("Mouse Y"), -1, 1) * verticalAimingSpeed * Time.deltaTime;
angleV = Mathf.Clamp(angleV, minVerticalAngle, maxVerticalAngle);
//if(zeroG == true){
angleF += Mathf.Clamp(Input.GetAxis("Yaw"), -1, 1) * horizontalAimingSpeed * Time.deltaTime; //
//}
}
// }
// Set aim rotation... this is the part where it gets set.
Quaternion aimRotation = Quaternion.Euler(-angleV, angleH, angleF);
Quaternion camYRotation = Quaternion.Euler(0, angleH, 0);
camera.rotation = aimRotation;
Setting the final rotation on local axis does not work.
I need to get that input in the Space.Self basically.
What are you useing to make the rotation because that is missing from your code. i.e Transform.rotate() or rotation = quaternion
Ok will update with more of the code... 1$$anonymous$$. Updated!
Answer by Runalotski · Aug 03, 2015 at 07:26 PM
Okay I have got this
//set veribales to zero each frame so that it will only read a number
//when the mouse moves
float angleH = 0f, angleV = 0f, angleF = 0f;
if(controlable){
angleH += Mathf.Clamp(Input.GetAxis("Mouse X"), -1, 1) * horizontalAimingSpeed * Time.deltaTime;
angleV += Mathf.Clamp(Input.GetAxis("Mouse Y"), -1, 1) * verticalAimingSpeed * Time.deltaTime;
angleV = Mathf.Clamp(angleV, minVerticalAngle, maxVerticalAngle);
//if(zeroG == true){
angleF += Mathf.Clamp(Input.GetAxis("Yaw"), -1, 1) * horizontalAimingSpeed * Time.deltaTime; //
//}
}
// }
// Set aim rotation... this is the part where it gets set.
//these two are now not needed
Quaternion aimRotation = Quaternion.Euler(-angleV, angleH, angleF);
Quaternion camYRotation = Quaternion.Euler(0, angleH, 0);
//change this line from .rotation to .rotate
Camera.main.transform.Rotate(-angleV, angleH, angleF, Space.Self);
Ok this kinda screws things up for me, BUT it fixes the axis thing.The rest of the code gets screwed because now it does not pivot.
However it still helps so thanks. I will up vote.
Its a 3rd person camera which rotates around the player. The camera position does not change when using this new rotate.
Don't know why, the aimRotation is used but never changed. The rotation of the camera itself is not used by any of camera position code, but but stops it from working.
I will post the rest of the code.
//This is where the camera changes position for 3rd person view.
smoothPlayerPos = Vector3.Lerp(smoothPlayerPos, player.position, smoothingTime * Time.deltaTime);
smoothPlayerPos.x = player.position.x;
smoothPlayerPos.z = player.position.z;
Vector3 farCamPoint = smoothPlayerPos + camYRotation * pivot + aimRotation * camOffset;
Vector3 closeCamPoint = player.position + camYRotation * closeOffset;
float farDist = Vector3.Distance(farCamPoint, closeCamPoint);
maxCamDist = $$anonymous$$athf.Lerp(maxCamDist, farDist, 5 * Time.deltaTime);
// $$anonymous$$ake sure camera doesn't intersect geometry
// This is to check if intersects with something...
RaycastHit hit;
Vector3 closeToFarDir = (farCamPoint - closeCamPoint) / farDist;
float padding = 0.3f;
if (Physics.Raycast(closeCamPoint, closeToFarDir, out hit, maxCamDist + padding, ~camLayer$$anonymous$$ask)) {
maxCamDist = hit.distance - padding;
}
currCamPose = closeCamPoint + closeToFarDir * maxCamDist;
camParent.transform.position = transform.position;
cam.position = currCamPose; //Here is the final position code....
make a new gameobject called pivot and child this to you character
now child the main camera to the pivot game object where ever you want
now attach your rotate camera script to the pivot game object and it will make the camera orbit it
what i mean is make the pivot rotate ins$$anonymous$$d of the camera