x


How would i lock a desired axis?

I would like to know how to lock an axis to keep an object from rotating on it. I am using JavaScript and I need the Z axis to be locked, due to the Z axis's value changing during the rotation of the X and Y axis's due to joystick I am new to Unity3D and scripting altogether but so far this is the only trouble i have came across. Thanks in advanced; Dylan Wright

more ▼

asked Mar 20 '10 at 05:11 AM

user-1559 (google) gravatar image

user-1559 (google)
1 1 1 1

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

3 answers: sort voted first
more ▼

answered Mar 20 '10 at 02:31 PM

e.bonneville gravatar image

e.bonneville
5.7k 100 116 165

i couldn't get anything out of them i tried some of the codes but my object still rotated on the Z axis some when i moved the joystick up adjusting the Y axis. If it helps i'm looking for something like the MouseLook Script but i can't use it on this object because I've used it on another object and it produces errors when used on two objects.

Mar 20 '10 at 03:19 PM user-1559 (google)
(comments are locked)
10|3000 characters needed characters left
more ▼

answered Mar 20 '10 at 07:03 AM

StephanK gravatar image

StephanK
6k 40 53 93

i checked that out but it says thats for position but i tried to change "position" to "rotation" and it didn't work for some reason, it looked like it would, here is my script :

var speed = 3.0; var rotateSpeed = 3.0;

function Update () {

    var controller : CharacterController = GetComponent(CharacterController);

    transform.Rotate(Vector3.up, Input.GetAxis ("J1Up") * rotateSpeed, 0);

}

Mar 20 '10 at 01:48 PM user-1559 (google)

You are using '0' as 3rd parameter of the Rotate function. This is equal to Space.World. The default would be Space.Self and that should work for you. Space.World let's your object rotate around (0,1,0) regardless of your object's local y-axis. You should always use the built-in enums instead of ints. This helps clarifying your code a lot.

Mar 21 '10 at 05:58 PM StephanK
(comments are locked)
10|3000 characters needed characters left

I fixed it, for some reason when i duplicated the MouseLook Script before i must have left out something, if using the MouseLook script to control two different options with two different inputs just change this :

public class MouseLook : MonoBehaviour {

to something like this :

public class MouseLook2 : MonoBehaviour {

and it will work just fine. It did for me anyways. Thanks for the help though i figured it out on my own.

more ▼

answered Mar 20 '10 at 04:18 PM

user-1559 (google) gravatar image

user-1559 (google)
1 1 1 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:

x2245
x329

asked: Mar 20 '10 at 05:11 AM

Seen: 4601 times

Last Updated: Apr 16 '10 at 05:20 PM