- Home /
changing velocity through scroll wheel
I have a flying script that works well but I need to be able to adjust the speed to some maximum value when you scroll up and be able to go backwards if you scroll down past zero. Right now I have it where it reads the input of the scroll wheel but it only moves as I roll the scroll wheel and doesn't move when I am not scrolling. How do I get it to change its velocity and not just move it with the scroll wheel? here's the script:
var rotateAmount = -5.0; function FixedUpdate() { // Turn var h = Input.GetAxis("Mouse X"); var v = Input.GetAxis("Mouse Y");
rigidbody.AddRelativeTorque(0, h 20, v 20); // Other way you may like //transform.Rotate(0, h 20, v 20); engine=Input.GetAxis("Mouse ScrollWheel");
rigidbody.velocity = transform.right * engine*5;
//Also if transform.forward doesn't work try transform.right
if (Input.GetAxis("Horizontal") < 0)
{ transform.Rotate(rotateAmount, 0, 0);
}
else if (Input.GetAxis("Horizontal") > 0) transform.Rotate(-rotateAmount, 0, 0);
}
ignore any odd negatives. My model had some of the axis backwards so I had to switch some signs. Hope someone can help! Thanks:)
Answer by Justin Warner · Mar 31, 2011 at 03:21 PM
Alright...
var speed = 1;
function Update () {
if(Input.GetAxis("Mouse ScrollWheel") > 0){
speed++;
}
else if(Input.GetAxis("Mouse ScrollWheel") < 0){
speed--;
}
print(speed);
}
That shows a very raw and basic form of it... But, you can then implement it however you think's best.
Good luck!
Answer by Justin Warner · Mar 31, 2011 at 02:34 AM
Assuming you know how you're going to make him go forward (Can't see it in your code... I'm a little bad at reading code haha)...
http://answers.unity3d.com/questions/6106/implementing-the-scrollwheel
That'll help with the scroll wheel... Did you need more help? Like, do you know how to make him go forward? Or no? Sorry. Hope this helps though. Comment if you need more.
it already goes forward and rolls with the a and d keys. the part that says rigidbody.velocity = transform.right * -10; is what controls it moving forward with the 10 being the velocity. i'll take a look at this though.
Alright, then in this case, change the -10 to var speed, and have that increase/decrease... to check bounds, put it in 2 if statements in the update function for if it's lower/higher, change to the lowest/highest it can go... If that makes sense. =).
yup it does. its bed time for me but i'll play with this tomorrow. thanks!
I made some changes. I can't get the scroll wheel to work properly. I can get it to read the input and all but not actually change the velocity just move it when I scroll.
Your answer
Follow this Question
Related Questions
Flying AI Shooting Help 1 Answer
Setting Scroll View Width GUILayout 1 Answer
Can someone help me fix my Javascript for Flickering Light? 6 Answers
Camera, Offsetting the Transform.LookAt 2 Answers
How i make this code in Unity Javascript 2 Answers