|
In my script, the player hits "s" to rotate 180 degrees. However, if they press "s" again, they rotate 180 degrees again. I don't want them to be able to rotate again. What am I missing? See script below:
(comments are locked)
|
|
I'm guessing the problem is that the player will turn 180˚ each frame. I also assume that the player is allowed to turn more than once, so say about half a sec after the first turn he can turn again.. If this is the case then the following should work: If you only want the player to be allowed to turn once (and then not again), then you can just use a simple boolean. e.g. Thank you for the response. The 2nd script you listed works best for me. However, I should have been clearer. My fault. I don't want the player to permanently lose the ability to rotate when pressing "s". I just want to make sure that if the object is already rotated into the correct position, player input from the "s" key will be ignored. If the object is not rotated in the correct position, I want the "s" key to function again. Thanks again. Any help is greatly appreciated.
May 01 '12 at 10:30 PM
shawnkilian
(comments are locked)
|
|
you could simply add a check to see what the current rotation is: var currentRotation = transform.rotation.y; if(Input.GetKeyDown("s") && ignore == false && currentRotation < desiredMaxRotation) (where desiredMaxRotation is a float) Thank you for the response. I am not sure where I should add this code. In my current script? As a new script? If I should add it to my current code, where should I place the two lines of code? I gave it a shot many times but I keep getting errors. Please let me know if you can help. Thank you!
May 01 '12 at 11:09 PM
shawnkilian
(comments are locked)
|
|
attach it to the object that should rotate: a couple of notes: this should technically work, assuming your starting rotation y value is less than 180, since if it hits 360 it'll flip over to zero. Not really good code overall, but should serve as an example Thank you. It helps me understand it better. However, I still cannot get the script to work. I get the following error: Assets/test.js(14,71): BCE0005: Unknown identifier: 'time'. I will keep playing with it. Thank you so much for all your help.
May 01 '12 at 11:57 PM
shawnkilian
Oops,sorry it was a syntax error, totally my fault, I fixed it now, try again, sorry!
May 02 '12 at 07:37 AM
Seth Bergman
(comments are locked)
|
