Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by cidmodder · Mar 31, 2011 at 02:19 AM · javascriptflyingscroll-wheel

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:)

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

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!

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

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.

Comment
Add comment · Show 4 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image cidmodder · Mar 31, 2011 at 02:38 AM 0
Share

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.

avatar image Justin Warner · Mar 31, 2011 at 02:50 AM 0
Share

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. =).

avatar image cidmodder · Mar 31, 2011 at 03:37 AM 0
Share

yup it does. its bed time for me but i'll play with this tomorrow. thanks!

avatar image cidmodder · Mar 31, 2011 at 02:41 PM 0
Share

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

Hint: You can notify a user about this post by typing @username

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

Answers Answers and Comments

No one has followed this question yet.

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges