x


Use lookAt and transform.translate at the same time

Hi, I'm trying to get a camera, pointing down towards a rectangle, to move on the x axis using the accelerometer and, at the same time, to always point at the center of the rectangle (which is, coordinates 0,0,0). So, the camera should move and rotate to always look at the center of the rectangle. The purpose is to give a sense of "false 3D", for lack of a better description.

I can make the camera move, but I can't make it rotate accordingly. When I use lookAt, the whole thing spins on the y axis instead of rotating on z axis. It looks like I can't use transform.translate and lookAt in the same function.

I'm really at a loss, here. I literally can't think of any way to fix this. It would be awesome if someone could help.

Anyway, here is the code I'm using to make it move. What should I add/change?

function Start () {

}
var camSpeed = 20;

function Update () {

//var dir : Vector3 = Vector3.zero;
var dir : Vector3;
dir.x = -Input.acceleration.y; 
dir *= Time.deltaTime;
transform.Translate (dir * camSpeed);

}
more ▼

asked Jul 26 '12 at 09:20 PM

ferruccio gravatar image

ferruccio
3 1 2

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

Your problem is using Translate without a specific second parameter of Space.world - currently the translation happens in the rotation of the object - which gives you the spinning effect. You presumably want movement in world coordinates and then the look at should keep it centered...

more ▼

answered Jul 26 '12 at 09:22 PM

whydoidoit gravatar image

whydoidoit
33k 11 23 98

Thanks! I also had to change another couple of things (which is, the orientation of the objects and the gravity), but now the whole scene is better layed out and it works perfectly. Thanks again!

Jul 29 '12 at 09:58 PM ferruccio
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x5061
x2988
x722
x327
x204

asked: Jul 26 '12 at 09:20 PM

Seen: 339 times

Last Updated: Jul 29 '12 at 09:59 PM