x


LookAt Enemy without orbit?

Hello guys.

Im currently working on a melee combat project, I am almost done but I have just found a problem, I want to be facing the Enemy during the combat, for that I used LookAt() when the enemy is in a certain range. The problem is that, when the enemy is in range I look at him but my character starts like orbiting around him (horizontal and vertical), even if jump, this just gets off if I get him out of the range but how can I face him just in a horizontal way?

Any idea? Thanks

more ▼

asked Apr 16 '12 at 05:31 PM

Noah 1 gravatar image

Noah 1
1.1k 33 45 50

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

1 answer: sort voted first

This has been asked many times.

http://answers.unity3d.com/questions/13974/how-to-use-the-lookat-function.html

basically you just bring the two position to the same y-level so it only rotates around the y-axis.

// C#
Vector3 lookTarget = target.transform.position;
lookTarget.y = transform.position.y;
transform.LookAt(lookTarget);


// UnityScript (JS)
var lookTarget : Vector3 = target.transform.position;
lookTarget.y = transform.position.y;
transform.LookAt(lookTarget);
more ▼

answered Apr 16 '12 at 05:48 PM

Bunny83 gravatar image

Bunny83
45.2k 11 49 207

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

x329
x106
x37

asked: Apr 16 '12 at 05:31 PM

Seen: 392 times

Last Updated: Apr 16 '12 at 05:48 PM