Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 gunboldb · Oct 08, 2018 at 10:48 PM · movement3dcontrols

Make object continue to move up as long as button is pressed

Hi,

Sorry for the noob questions but I have a bird in a third person view. And when I press and hold W I want the bird to fly up continuously until I release W at which point the bird should glide down (bird has gravity).

I am having a bit of a hard time making the bird go up continuously. Everything else works fine.

I have tried using transform.Translate, rigidbody.AddForce, and CharacterController but my solutions are not working as I want them to.

With how it is right now, when I press and hold W the bird moves up but stops going up after a certain point and begins to fall down even if I am still holding the W key. And when it is falling, if I press W it does not go up again, it will fall to the ground, and only when it is on the ground I can make it go up again. Which seems quite strange to me...

Anyone have any suggesions?

1.

 if (Input.GetKey(KeyCode.W))
         {
             anim.SetBool("isFlying", true);
 
             transform.Translate(Vector3.up * Time.deltaTime, Space.World);
         }

2.

 if (Input.GetKey(KeyCode.W))
         {
             anim.SetBool("isFlying", true);
 
             transform.Translate(new Vector3(0, speed * Time.deltaTime, 0));
         }

3.

 if (Input.GetKey(KeyCode.W))
         {
             anim.SetBool("isFlying", true);
 
             rigidBody.AddForce(new Vector3(0f, flyUpForce, 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

3 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by bennett_apps · Oct 08, 2018 at 11:10 PM

try Debug.Log...is your code actually executing?

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 gunboldb · Oct 08, 2018 at 11:16 PM 0
Share

I think it is executing because the animation plays just fine and it does go up, But the problem is that it does not continuously go up, after a certain height it just drops on its own. And when it is dropping, even if I press W again it just continues to fall.

avatar image bennett_apps gunboldb · Oct 08, 2018 at 11:21 PM 0
Share

that happens with all three examples? Same result?

avatar image gunboldb bennett_apps · Oct 08, 2018 at 11:37 PM 0
Share

Yes, all three are behaving the same

avatar image
0

Answer by JoelGab · Oct 09, 2018 at 12:55 AM

My guess is code somewhere else in your project is resulting in the odd behaviour. The fact you said it stops at a certain point makes me believe some code, somewhere else is doing that.

Comment
Add comment · Show 2 · 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 gunboldb · Oct 09, 2018 at 01:02 AM 0
Share

Right, so in theory the above codes should work to get the effects I am describing?

avatar image JoelGab gunboldb · Oct 09, 2018 at 03:51 AM 0
Share

Yes, Assu$$anonymous$$g no other code is applying a downward force exponentially, which might be why you inevitably start to sink down. If you coded your own gravity maybe look into the logic there.

avatar image
0

Answer by JusSumGuy · Oct 10, 2018 at 05:31 AM

Are all these if statements in the Update function? if so that's the problem.

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 JusSumGuy · Oct 10, 2018 at 05:41 AM 0
Share

To clarify, if the if statements are not in the Update function that's the problem. lol

avatar image JoelGab · Oct 10, 2018 at 06:13 AM 0
Share

@JusSumGuy That wouldn't make sense, because it wouldn't be triggering at all if it was not Update.

avatar image JusSumGuy · Oct 10, 2018 at 07:16 AM 0
Share

Just wanted to make sure you didnt put it in Start

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

154 People are following this question.

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

Related Questions

Mecanim: Baked transforms in animation or No? 0 Answers

How do i move around in the editor without using arrow keys or middle click. 1 Answer

How to apply equal force back to player when colliding with a wall? 2 Answers

Vector3 MoveTowards character flying up when told to follow,Vector3 MoveTowards object flying up when I press play 0 Answers

How do i maintain the same speed in the air? 1 Answer


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