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 /
  • Help Room /
avatar image
0
Question by Jace-Paxz · Jul 15, 2017 at 01:26 PM · charactercontrollervelocityaddforcegetaxisgetkeydown

need help badly

im practicing unity can anyone show me example c# script of this. i want when i press space 1 time the object will go all the way up and while the object is going up and i press the space again the object will go all the way down.

hope some1 can help. thank you in advance

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
0

Answer by Ady_M · Jul 15, 2017 at 03:01 PM

Ask smaller and more precise questions.
Try to solve one small part at a time.
Also, I would recommend that you try to find a better title for your topic/question, like "Moving an object over time from one position to another"

Topics in your question:

Moving objects every frame:

  • Vector3.MoveTowards

  • Transform.Translate

Reacting to player input:

  • Input.GetKeyDown

States (is it on its way up or down):

  • Using IF-statements and variables (YouTube video) - I did not spend much time looking for the perfect tutorial on using IF-statments for beginners.

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 Jace-Paxz · Jul 15, 2017 at 03:56 PM 0
Share

hi thank you for your reply and im sorry im totally newbie to unity or game development but i want to learn. anyway ill try to check and study the topics you have suggested and see if it can be use to something i want..

what i really wanted is to make an object move all the way up or down with single keycode until there is collisions. its basically to avoid collisions.

again thank you.

avatar image Ady_M Jace-Paxz · Jul 15, 2017 at 04:04 PM 0
Share

Hmm, let me see if I understand you correctly. All movement is done instantly. Pressing the key should try to instantly move the object to its destination, not over time. But if the object hits something half way up then the object should stop there. Is that correct?

avatar image Jace-Paxz Ady_M · Jul 15, 2017 at 04:29 PM 0
Share

no sir, what i meant is, pressing the key (example "space") the object should fly up and when you press the key again (the space) it should fly down. like press space 1 time to move the object to the left and will not stop until you press the space again to go in the opposite direction..

avatar image
0

Answer by Shifty-Geezer · Jul 15, 2017 at 04:14 PM

Sounds like a Flappy Bird zig-zag to me. You should create a vector for movement, and change it every time you press a button. Something like:

     Vector3 direction = new Vector3(0,1,0);
     float speed = 0.01f;
     
     void Update(){
         if (Input.GetKeyDown(KeyCode.Space)) {
             direction.y *= -1;
         }
     
         transform.position += direction*speed;
     }

This checks the space key and, if down, inverts the direction. Every update it moves the object by 'speed' distance. This doesn't factor in screen refresh.

To be honest though, you really need to work through the tutorials to learn the basics of Unity. This is something that you should be able to work out for yourself from the documentation and online tutorials, because creating a game gets infinitely more complex than this! You'll have to spend and effort learning the basics up to moderate ability as otherwise you'll be asking questions like this all the time! ;)

Comment
Add comment · Show 1 · 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 Jace-Paxz · Jul 15, 2017 at 04:37 PM 0
Share

hi sir thank you for your answer and i will try those. and yes i am studying through tutorials but i was just curious about this 1 because i haven't seen 1 yet. so usually the so called " jump" is going up yeah? and usually whats most used for the object to go down gravity fall. is it possible to give an object a jump but going down??

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

80 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

Related Questions

Using "AddForce" with a Character Controller 1 Answer

How do I create Sling-Shot like propulsion? 1 Answer

How to speed up an object with AddForce? 1 Answer

How to create smooth jump with rigidbody.addforce? 2 Answers

How control Rigidbody2d using GetAxis with AddForce and angularVelocity (2D) 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