Rotate.Around Questions

Ok so basically I was working on a fps camera control script for the iphone because the one in the occlusion demo was kinda bad (jerky movement). So after a lot of work (on and off) I figured the best way to make it smooth was to just move a cube in front of the camera and just make the camera lookat it. I just added the touch.deltaposition to the cube (divided by a number so it wasn’t flying all over the place), worked awesome. But I really want 360 degree look (kinda pointless otherwise), I tried Rotate.Around but thats for more continuous rotation, is there anything like that that would work in my case?

I tried using transform.translate in combination with the cube looking at the camera for local position changes and it kinda worked but was a tiny bit jerky and the more you rotated it the more the cube moved away from the camera (for some reason). Any tips?

Thanks.

There are a few basic concepts on how cameras should work. You can “rotate” them around things, or you can calculate the rotation, then get the position based on the rotation, or you can calculate the rotation then force the position. All are valid methods if used in the correct context.

On almost all of the cameras I create now, they are controlled by the thing that they are to be looking at. I rarely use an external camera controller. I found them to be buggy as Unity does not always follow the same path for running scripts. This causes jitteryness that is highly undesirable.

I also use the method of calculation of the rotation, then translation on the distance. This gives me some advantages. 1) It is incredibly easy to understand, and 2) I can use the two points in a Line or Raycast to check for obstruction.

The basics are:
Set the camera’s rotation according to the X and Y inputs.

x += Input.GetAxis("Mouse X") * xSpeed * 0.02;
y -= Input.GetAxis("Mouse Y") * ySpeed * 0.02;
y = ClampAngle(y, yMinLimit, yMaxLimit);
var rotation = Quaternion.Euler(y, x, 0);
Camera.main.transform.rotation = rotation;

static function ClampAngle (angle : float, min : float, max : float) {
	if (angle < -360)
		angle += 360;
	if (angle > 360)
		angle -= 360;
	return Mathf.Clamp (angle, min, max);
}

Set the position of the camera to the target

Camera.main.transform.position = transform.position;

Run calculations for distance (this would be where you would use a linecast from the point the camera is now, to the point where it should be)
NOTE: In calculation for Raycasts/Linecasts always use the distance - 1. This will allow you to set the distance to hit - 1 if you happen to hit something.

Lastly, just move the camera the distance needed.

Camera.main.transform.Translate(Vector3.back * distance);

Hi, I’m new about Unity and I have a question about this topic (I hope it’s correct to post it here).

What about calculate rotation and position at the same time, in order to have smooth movements and rotations together?
I’m working on a project where I have a GUI with a number of buttons that activate/deactivate specific actions in my scene. One of them should trigger a smooth movement + rotation of the camera along more than one axes, from one fixed position (and rotation) to another, but I haven’t yet found any example that shows something similar, also because often position and rotation are calculated according to the mouse movements or along one single axis, that is not my case.

I’ve written a jscritp function that is triggered by a button and moves the camera, but I don’t know how to add the rotatation. I know that it’s probably more correct to have those kind of instructions inside the Update of LateUpdate function and I’ve tried it, but I still haven’t clues about how to combine the rotation with the translation.

function CameraMovement()
{
	var startTime = Time.time;
	var startPoition = movementTarget.transform.position;
	
	var targetPosition = GameObject.Find("main_cam").transform.position;
	
	while (Time.time<startTime+1.5)
	{
		var i=(Time.time - startTime);
		movementTarget.transform.position = Vector3.Lerp(startPosition, targetPosition, i);
		yield;
	}
}

I was wondering if it is possible to have a movement that resemble a flying through, with smooth rotations and translations of the camera at the same time from one position to another.
Can someone give me a hint about how to solve this problem?