|
Hi, I have a spaceship that rotates on the z axis with a max of 30 degrees when the Horizontal axis is held down to give the effect of roll like an airplane. How can I make my object rotate back to 0 degrees when the Horizontal axis is released? So the object only rotates while the left/right keys are held and then it slowly rotates back to 0 when these keys are let go? Cheers.
(comments are locked)
|
|
How about this- instead of using the Horizontal axis directly, have the Horizontal axis define a "target roll"- this determines how far you want the spaceship to bank. Then in your Update function interpolate between your current roll and the target roll using a function like Mathf.Lerp or Vector3.Lerp. Or, better still, you could weight it so that the interpolation amount changes depending on how much of the axis is pressed- so that if the axis is at full lock it interpolates fast, and if the axis is at zero it interpolates slowly, something like this- Thanks syclamoth! Only problem is that it will only rotate in one direction currently, I need to set the target angle as -30 but I can't figure out how to make this work?
Sep 18 '11 at 01:42 AM
stuthemoo
Input.GetAxis("whatever") should return a value between 1 and -1. Have a look at how your axis is set up, and see if there's anything limiting its rotation!
Sep 18 '11 at 04:33 AM
syclamoth
@stuthemoo: Use comments if you need further information. The Answer button is dedicated for actual Answers to the question. If you have another question you should ask a new seperate question. If you need more help with this question use comments or edit your question to improve it.
Sep 18 '11 at 04:36 AM
Bunny83
No, my Horizontal axis is set up fine and works for the movement of the spaceship. When I use log.debug to show the value of targetAngle i am getting negative numbers one way and positive numbers the other. Are you sure theres nothing in the script that could be causing this? Sorry Bunny83 that was an accident :/
Sep 18 '11 at 09:12 AM
stuthemoo
Put Debug.Log lines inbetween every line of code- this way you can find out exactly what is happening everywhere! I don't know why it isn't working properly- unless I had the code right in front of me, I can't work out what the problem is. How are you implementing the final value?
Sep 18 '11 at 09:43 AM
syclamoth
(comments are locked)
|
