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 herp johnson · Aug 16, 2012 at 08:28 PM · movementinputsmoothhelicopter

Smooth movement help?

Hello, I have a helicopter script and I want the the helicopter to smoothly speed up while a key is pressed, and right after JUST that key is let up, I want it to smoothly stop moving in that direction. Again, I want to be able to have each key's action independently and smoothly speed up and stop movement in that certain direction.

Here's a sample of what I have so far. Right now movement is rare and completely unpredictable/glitchy.

     (In Update function)
 
     // up
     if (Input.GetKey("up"))
     {
           Apache.rigidbody.constantForce.force.y = 300;
           upPressed = false;
     }
     
     if (Input.GetKeyUp("up"))
           upPressed = true;
           
 
     //down
     if (Input.GetKey("down"))
     {
           Apache.rigidbody.constantForce.force.y = -300;
           downPressed = false;
     }
     
     if (Input.GetKeyUp("down"))
           downPressed = true;
 
 
 //Movement realism: this smooths out all movements and rotations.
 
     if ((upPressed || downPressed) && Apache.rigidbody.velocity.y > 0 )
         Apache.rigidbody.constantForce.force.y = -100;
     
     if ((upPressed || downPressed) && Apache.rigidbody.velocity.y < 0)
         Apache.rigidbody.constantForce.force.y = 100;
     
     else if ((upPressed || downPressed) && Apache.rigidbody.velocity.y == 0)
         Apache.rigidbody.constantForce.force.y = 0;
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by donhelms · Aug 16, 2012 at 09:11 PM

Have you tried using

 rigidbody.AddForce(yourforce,ForceMode.Impulse);

Also, what is the mass of the body?

Is your rigid body to proper scale in meters with regards to an actual helicopter?

Comment
Add comment · Show 3 · 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 herp johnson · Aug 16, 2012 at 09:24 PM 0
Share

rigidbody.addforce creates an immediate motion change doesn't it? i want constantforce because it was (vaguely) recommended by unity for that kind of movement. I haven't really given much thought to the mass or scale. Right now the scale is 500 because It's easier to navigate the view of the helicopter when it's big. The mass is 50.

avatar image donhelms · Aug 16, 2012 at 09:33 PM 0
Share

Well, thinking of the propeller of a chopper, it's actually creating 'pulses' of downward force much in the way that an impulse force would work. It's the accumulation of these 'impulses' from the choppers blades that elevate the aircraft so if you model your bodies correctly in proportion of scale/weight, it may work.

The physical properties of the rigid body can potentially be the source of the erratic behavior you see. If I were you, i'd start by making sure your helicopter rigid body is the same size/scale of a real helicopter.. if a Apache is 50 meters long, then make sure your model/rigid body is 50.

Remember that the physics engine is coded to real world physics so it assumes that your scales/weights are correct as well.

avatar image herp johnson · Aug 16, 2012 at 10:00 PM 0
Share

So it can compute lift if the blades are correctly shaped?? Wow! Well, there's only so much I can do with unity and scripting, I'm only 17, haha. Currently, for my rotors, I'm using a hingejoint motor and adding force to it. What I'm concerned with is the input of my code and having the output be dependable. Right now, for example, holding the Up key works, but after you use that key, if you press Down, it won't move. I just want to optimize my code so that that stops happening.

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

9 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to Move a Cube 3 Answers

Stopping an object immediately 1 Answer

Speed pickup 1 Answer

How to incorporate Time.deltaTime into existing script 1 Answer

Change a float smooth 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