Quantcast
Channel: Questions in topic: "local axis"
Viewing all articles
Browse latest Browse all 106

Camera Limitations Using Inverse Vectors

$
0
0
My code works fine with some world orientations but somehow it doesnt works with other orientations. I have a camera , camera target pivot point and camera offset borders along to the that pivot point. The camera must be able to move freely within the boundaries of the red line. Here is my scene setup ![alt text][1] [1]: /storage/temp/181597-ddddd.png **YELLOW DOTS Camera Position Points GREEN DOTS Camera Look Rotation Points RED DOTS Camera Borders** Number 1,2 charts works fine as i expected camera doesnt go out of that red borders but the other ones 3-4 camera somehow will stuck on z or x axis . Here is my camera movement code . **CAMERA MOVEMENT** private void MoveCamera(Vector3 force, float sens) { Chart currentChartObj = currentChart.GetComponent(); Vector3 desiredForce = new Vector3(force.x,force.y,0) * Time.deltaTime * sens; Vector3 currentNormalPos = currentChart.transform.position + currentChart.transform.TransformDirection(currentChartObj.positionOffset); cameraTransform.transform.Translate(desiredForce); Vector3 currentTempPos = cameraTransform.transform.position; float finalX = Mathf.Clamp(currentTempPos.x, (currentNormalPos + currentChart.transform.InverseTransformVector(-Vector3.right * currentChartObj.cameraBorderOffsets.x)).x, (currentNormalPos + currentChart.transform.InverseTransformVector(Vector3.right * currentChartObj.cameraBorderOffsets.x)).x); float finalY = Mathf.Clamp(currentTempPos.y, (currentNormalPos + currentChart.transform.InverseTransformVector(-Vector3.up * currentChartObj.cameraBorderOffsets.y)).y, (currentNormalPos + currentChart.transform.InverseTransformVector(Vector3.up * currentChartObj.cameraBorderOffsets.y)).y); float finalZ = Mathf.Clamp(currentTempPos.z, (currentNormalPos + currentChart.transform.InverseTransformVector(-Vector3.right * currentChartObj.cameraBorderOffsets.x)).z, (currentNormalPos + currentChart.transform.InverseTransformVector(Vector3.right * currentChartObj.cameraBorderOffsets.x)).z); Vector3 finalPosition = new Vector3(finalX,finalY,finalZ); cameraTransform.transform.position = Vector3.Slerp(currentTempPos, finalPosition, 0.125f); } I am so confused about local and global and local world spaces... Thanks in advance !

Viewing all articles
Browse latest Browse all 106

Latest Images

Trending Articles





Latest Images