x


Rotation of object

Hi! I have a component that acts an analogic joystick and i player character that should rotate accordingly with the movement of the joystick object.

In a 2d game i would get the tangent of the x and y of the joystick to get the angle and apply it to the object. But here i don't understand how to do that with quaternions...

Right now i got the direction working so i already have the Vector3 that i would need to use to calculate the rotation.

Suppose my direction vector is (10,0,10) so my player is moving up-right(from my over the head view) i would need him to face that direction also.

Thanks in advance.

more ▼

asked Nov 19 '09 at 12:24 PM

pablo gravatar image

pablo
14 6 6 8

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

2 answers: sort voted first

Simply use Quaternion.LookRotation(directionVector).

more ▼

answered Nov 19 '09 at 12:59 PM

jonas echterhoff gravatar image

jonas echterhoff ♦♦
9.8k 7 23 104

Hi, thanks, i am trying that but it is working weird... var rot : Quaternion = Quaternion.LookRotation(dest, Vector3.up); transform.rotation =rot;

doing this is also modifyng the direction of the projectile besides the rotation, don't know why...

Nov 22 '09 at 02:26 AM pablo

I don't quite understand. It is modifying the direction besides the rotation? What is the difference between direction and rotation?

Nov 22 '09 at 11:00 AM jonas echterhoff ♦♦
(comments are locked)
10|3000 characters needed characters left

Simply use Quaternion.LookRotation(directionVector). jonas echterhoff

Hi, thanks, i am trying that but it is working weird... var rot : Quaternion = Quaternion.LookRotation(dest, Vector3.up); transform.rotation =rot; doing this is also modifyng the direction of the projectile besides the rotation, don't know why... pabloruiz55

Try checking the Freeze Rotation box in the rigidbody of your projectile. This should fix your projectile from rotating with the parent.

more ▼

answered Dec 03 '09 at 12:50 AM

Vagabond_king gravatar image

Vagabond_king
17

Sorry for the late reply, it was working wrong because of an error somewhere else, sorry my bad. Thanks!

Dec 03 '09 at 01:56 AM pablo
(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:

x5273
x2245

asked: Nov 19 '09 at 12:24 PM

Seen: 2650 times

Last Updated: Nov 20 '09 at 12:53 PM