ganon
November 19, 2009, 1:22pm
1
Hi All,
My name is Sebastián Gana, i’m from Santiago Chile.
My native languaje is spanish but i’ ll try to explain my problem.
I see the post : http://forum.unity3d.com//viewtopic.php?t=14293 and example : http://www.grayboxgames.com/GBG/Tests/GrabNRotate.html , and now i try to make the same think for a standalone demo (not iPhone), without moving the earth, only moving the camera around the pivot center.
I try this script example : http://www.unifycommunity.com/wiki/index.php?title=MouseOrbitImproved , and works fine, but the problem is when i set a new elevation position (y mouse axis), my camera orbit around an imaginary north.
Someone can help me with this?
Any ideas?
Thanks!!
pd: Sorry my bad english.
I think the problem might be that this script uses Euler angles to set the rotation axis of the camera. Try using the camera’s transform.up property as the axis of rotation and use Quaternion.AngleAxis to calculate the rotation.
ganon
November 19, 2009, 6:31pm
3
Check this…
I solved the rotation part with the following code,
But now i’m trying to resolve the distance to target (pivot) point.
Have any idea??
Thanks!
using UnityEngine;
using System.Collections;
public class SomeCamera: MonoBehaviour
{
public Transform target;
public float radioInit = 100.0f;
public float radioMin = 55.5f;
public float radioMax = 117.5f;
public float mouseXSpeed = 1.0f;
public float mouseYSpeed = 120.0f;
public float mouseWheelSpeed = 5.0f;
float radio = 0.0f;
float x = 0.0f;
float y = 0.0f;
Vector3 targetPos = new Vector3(0.0f, 0.0f, 0.0f);
Vector3 cameraUp, cameraRt;
// Use this for initialization
void Start()
{
radio = radioInit;
targetPos = target.position;
cameraUp = transform.up;
cameraRt = transform.right;
}
// Update is called once per frame
void LateUpdate()
{
if (target)
{
radio = Mathf.Clamp(radio - Input.GetAxis("Mouse ScrollWheel") * mouseWheelSpeed, radioMin, radioMax);
if (Input.GetMouseButtonDown(1))
{
cameraUp = transform.up;
cameraRt = transform.right;
}
if (Input.GetMouseButton(1))
{
x = Input.GetAxis("Mouse X") * mouseXSpeed * radio * 0.02f;
y = -Input.GetAxis("Mouse Y") * mouseYSpeed * 0.02f;
}
Vector3 radioPos = new Vector3(100.0f, 0.0f, 0.0f);
transform.RotateAround(targetPos, cameraUp, x);
transform.RotateAround(targetPos, cameraRt, y);
}
}
}
What problem do you have with the distance? Does the camera move in and out as it rotates?