x


What's wrong with my movement script?

Okay so I'm having trouble with this movement script. I'm a super beginner (actually I know nothing of scripting at all, and I got this from the Tornado Twins).

var speed : float = 3;
var rotateSpeed : float = 3;

function Update() {
    var controller : CharacterController = GetComponent( CharacterController );
    transform.Rotate( 0, Input.GetAxis( "Horizontal" ) * rotateSpeed, 0 );
    var forward = transform.TransformDirection( Vector3.forward );
    var curSpeed = speed * Input.GetAxis( "Vertical" );
    controller.SimpleMove( forward * curSpeed );
}

@script RequireComponent( CharacterController );

For some reason my character spins like a clock, instead of around the Y axis. Thanks for the help! -Rov

more ▼

asked May 04 '12 at 02:12 AM

Rovalin gravatar image

Rovalin
62 6 15 21

I can tell you what's wrong with your script: At the first glance i would say it's not formatted in a way we can read it, so let me fix that first...

May 04 '12 at 02:13 AM Bunny83
(comments are locked)
10|3000 characters needed characters left

3 answers: sort voted first

Well this is very helpful if you want to learn scripting in java, boo or C#.

http://unity3d.com/support/documentation/ScriptReference/

Have a look at this and make sure you closely study the scripts and see how they are made and what each function does. This site helped me alot when I first started out in unity.

more ▼

answered May 04 '12 at 04:54 AM

Ampler Games gravatar image

Ampler Games
108 19 30 34

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

Well if that's the only script that affects your player it's obviously that Input.GetAxis( "Horizontal") is returning a value != 0.

So you should check your InputManager how the virtual axis is defined. Watchout, an axis can appear multiple times for example one time with keys like "a" and "d" a second time with "left arrow" and "right arrow" and maybe another one for a joystick or something else.

more ▼

answered May 04 '12 at 02:18 AM

Bunny83 gravatar image

Bunny83
45.5k 11 49 207

Thanks, I check that out.

-Rov

May 04 '12 at 03:56 AM Rovalin

Also you should multiply the horizontal control by Time.deltaTime to make it framerate independent:

transform.Rotate( 0, Input.GetAxis( "Horizontal" ) * rotateSpeed * Time.deltaTime, 0 );
May 04 '12 at 05:20 AM aldonaletto
(comments are locked)
10|3000 characters needed characters left

I figured out it wasn't a problem with the script. Thanks for your help!

-Rov

more ▼

answered May 06 '12 at 03:10 PM

Rovalin gravatar image

Rovalin
62 6 15 21

It would be great when you could actually post what the problem was... otherwise this isn't really an answer to the question and it won't help others. So if you can find the time please edit your answer and add the details what the problem was and how you fixed it.

May 06 '12 at 04:48 PM Bunny83
(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:

x5091
x1371

asked: May 04 '12 at 02:12 AM

Seen: 253 times

Last Updated: May 06 '12 at 04:48 PM