x


Locking and then resetting one Axis - Yes, I know it's been asked a 100 times....

The locking part has and I do know the answer to that....Using a configurable joint and setting x,y,z motion and/or angularmotion to Locked or scripting to z=0 in the update.

This works for the most part but I've found that when I drag my player object across a ground plane with a collider, that the Z-axis (for me) shifts ever so slighty, so a value set to 1000 will end up at 1003. This is enough to send my player off the boundaries of my game plane.

Does anyone know how to constrain it to a value and if the value ends up slightly off it is automagically reset to 1000.

more ▼

asked Aug 05 '10 at 04:09 PM

Vitruvius gravatar image

Vitruvius
25 4 4 10

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

2 answers: sort voted first

Use this code (untested js):

function FixedUpdate() {
    transform.position.z = 1000;
}

or (again, untested js):

ground : GameObject;

function FixedUpdate() {
    transform.position.z = ground.transform.position.z + 0.1;
}

The first code constantly sets z to 1000. The second code constantly sets z to the height of your ground, whatever that may be. Pick the one you need.

more ▼

answered Aug 05 '10 at 04:54 PM

e.bonneville gravatar image

e.bonneville
5.7k 100 116 165

Thanks that did the trick. I would add that I also found that checking off 'Configured in World Space' in the Configurable Joint inspector seemed to constrain things better...but not perfectly like the above code. Also, it solved this crazy flickering problem I was getting when I was at the boundaries of my game and attempting to move my ship beyond the boundaries. It stopped it and now is all smooth and silky. :-)

Aug 05 '10 at 05:19 PM Vitruvius

Glad I could help you.

Aug 05 '10 at 06:44 PM e.bonneville
(comments are locked)
10|3000 characters needed characters left

you should do z=0 in LateUpdate().

more ▼

answered Aug 05 '10 at 04:18 PM

AliAzin gravatar image

AliAzin
2.5k 42 56 79

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

x64

asked: Aug 05 '10 at 04:09 PM

Seen: 771 times

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