x


Vertical Slider as rotater

Hello everyone, Im trying to rotate a Cannon of a ship for aiming adjustment. I tried first using the eulerAngle adjustment but it didn't work, the whole angles and quaternion still confuses me. :(

here's my current code:

public Transform leftCannons; // the actual cannon
public float leftCannonAngle = 0.0f; // the rotation of cannon
//On GUI area

leftCannonAngle = GUI.VerticalSlider (new Rect (250, 5, 10, 50), leftCannonAngle, 0.0f, 10.0f);
leftCannons.transform.Rotate(Vector3.forward, leftCannonAngle);

as you can see in the code i want to limit the rotation of the cannon between 0 deg and 10 deg of the z-axis.

more ▼

asked Aug 05 '10 at 04:55 PM

Clave gravatar image

Clave
37 3 4 10

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

1 answer: sort voted first

tranform.Rotate() does not set the rotation, it rotates the current transform by a value. If you want to force the z-axis rotation to be always the value of your slider, you could do:

Vector3 angles=leftCannons.localEulerAngles;
angles.z=leftCannonAngle;
leftCannons.localEulerAngles=angles;

(Note that since leftCannons is already of type Transform you don't need to write leftCannons.transform)

more ▼

answered Aug 05 '10 at 05:42 PM

Wolfram gravatar image

Wolfram
9.1k 8 20 53

Thank you very much! :)

Aug 05 '10 at 05:56 PM Clave
(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:

x5
x1

asked: Aug 05 '10 at 04:55 PM

Seen: 702 times

Last Updated: Aug 05 '10 at 04:55 PM