x


Rotate to look at with physics

I want to be able to have something to rotate to look at something, but I don't know how to make it accurate. I only want it to rotate on the Z axis. Any good way I could do this?

more ▼

asked Sep 11 '11 at 01:42 AM

The BOOM gravatar image

The BOOM
283 19 26 39

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

1 answer: sort voted first

You can calculate the direction of the target and zero the z coordinate - this restricts the direction to the XY plane. Then you can calculate a Quaternion.FromToRotation from what you consider your forward direction to the target - if the forward direction of your object is the X axis, for instance, you should use Vector3.right as from direction:

var target: Transform;
...
    var atDir = target.position-transform.position;
    atDir.z = 0; // restricts direction to the XY plane
    transform.rotation = Quaternion.FromToRotation(Vector3.right, atDir);
...
more ▼

answered Sep 11 '11 at 02:06 AM

aldonaletto gravatar image

aldonaletto
41.4k 16 42 197

I want to rotate with physics, not with transform.

Sep 11 '11 at 03:08 AM The BOOM

You have no reason to rotate with physics if you know the end result you're looking for. Physics should be used for unpredictable simulations. The results will be the same, you'd just be wasting CPU cycles using the physics engine.

Sep 11 '11 at 03:44 PM PrimeDerektive
(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:

x1869
x724
x48

asked: Sep 11 '11 at 01:42 AM

Seen: 860 times

Last Updated: Sep 11 '11 at 03:44 PM