x


Preventing "LookAt" from flipping?

Essentially I'm creating a 2D game with 3D graphics in Unity iPhone. To minimise the poly count I have cut the backs off many of the objects because you will only see them from the front. My problem is the "LookAt" code. I'm saying LookAt(Vector2) for a 3D arrow to look at something on the X and Y axis, the problem is when the object passes it on the x axis the arrow flips round to show the back of itself. So for example when the target is to the right of the Arrow its all fine but when it's to the left of the arrow it shows the back of the arrow. Does anyone have any idea how I can just limit the arrow to pointing towards the object and not rotating around itself?

Thanks in advance

more ▼

asked Aug 12 '10 at 02:36 PM

ROM gravatar image

ROM
262 46 49 58

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

2 answers: sort voted first

If I have understood the problem correctly, I think you could use this code instead of "LookAt"

var relativeUp = target.TransformDirection (Vector3.forward);
var relativePos = target.position - transform.position;
transform.rotation = Quaternion.LookRotation(relativePos,relativeUp);

You might have to change the Vector3.forward to something else, and/or add an amount of rotation, based on how your current setup is.

Does this solve the problem?

more ▼

answered Oct 29 '10 at 12:34 PM

Atnas1010 gravatar image

Atnas1010
1.1k 6 10 26

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

have you tried using a configurable joint assigned to the 3d arrow? You can use it to lock rotation to certain axes pretty easily.

more ▼

answered Sep 07 '10 at 07:13 AM

Ping gravatar image

Ping
1

(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:

x2174
x727
x329
x132
x49

asked: Aug 12 '10 at 02:36 PM

Seen: 1871 times

Last Updated: Aug 12 '10 at 02:36 PM