Newbie Question on Rotation

Hey there, thank you for taking the time to read this.

I’m making a revolving labyrinth and i want to make it rotate in on the left and right arrow.
im not succeeding in this.(since i just starting with scripting) anyone a idea on how to do this?

here is my piece of code:

function Update () 
	{
var e : Event = Event.current;
	if (KeyCode.RightArrow) 
		{
		transform.Rotate(0, 0,0+1);
		}
	if (KeyCode.LeftArrow) 
	{
	transform.Rotate(0, 0,0-1);
	}
}

thank you!

Event is for OnGUI code, not Update. Use the Input class in Update. Also, you need to make your code framerate-independent by using Time.deltaTime. It’s simpler if you just use 1 and -1 instead of 0+1 and 0-1. However it would be simpler still and allow more control by using the input manager settings if you used GetAxis:

transform.Rotate(Vector3.forward * Input.GetAxis("Horizontal") * Time.deltaTime);

–Eric

Thank you very much Eric, i will give that a try!

Hey Eric,

That works like a charm, but it moves very slowly.
Is there a away to make it a bit faster?

my code looks like this now (you really slimmed it down :slight_smile:

function Update () 
{ 
transform.Rotate(Vector3.forward * Input.GetAxis("Horizontal") * Time.deltaTime);
}

Add a speed multiplier:

var speed : float = 5.0f;
transform.Rotate(Vector3.forward * Input.GetAxis(“Horizontal”) * speed * Time.deltaTime);

Thank you Fizixman! that worked like a charm!

I put the var before “function update” so i could change the value in the editor (20 seams to be the sweet spot) but it works Yay!

i wish i knew what i all meant though :frowning:

learning is tough!

Here you can find the fruit of mine/our/you’re labour.
Its the first thing i made entirely by myself in unity (Ahum, except for the script)

http://building-site.nl/laby/WebPlayer.html

Its a mazething for low/medium level disabled people/children, should work on a touch screen in the fututre.

any toughed and/or suggestions are welcome

Things i need to change/add:

  • Textures (Unity doesn’t handle multi materials from 3dsmax?) (i prolly going to bake them)
  • play gear sound on rotation or key/mouse down
  • Make the gear rotate on mouse down on the smaller gears (counter-clockwise for the left on clockwise for the right one
  • create more levels
  • create GUI and title page
  • make it move faster
  • write some soothing musix and add audio
  • maybe more game-challenges
  • stuff i hadn’t think of yet

cheerio!
Alan