• 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 MobinS · Nov 10, 2011 at 07:42 AM · inputchangefloatverticalhorizontal

changing a float number by moving arrows (horizontal and vertical input)?

Hi I made a bullet and put this on prefab out of game. and I made a constant force for it and I put "10" for X force. now when I shoot it go forward in X line. and when I put X "9" and then put Y "1" the ball shot a little farther near Y line.. and when I continued this ( like this : X=10 Y=0 , X=9 Y=1 , X=8 Y=2 , X=7 Y=3 ... X=0 Y=10 ) it will change the direction of it.. and for other side I put -9 and -1 ... i work perfect and I put the numbers in float. when I change them like this Manually the work great. but I want that for example when I hold 'W' automatically set the X to 10 and Y to 0... when I hold 'W' and 'D' it automatically set X to 5 and Y to 5 too. I mean how should I change a float number using horizontal and vertical input the we use for moving around? thnx!

Comment
Add comment · Show 2
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 MobinS · Nov 11, 2011 at 04:31 PM 0
Share

any one?????

avatar image Julien-Lynge · Nov 11, 2011 at 06:57 PM 1
Share

$$anonymous$$obin,

I really can't understand what you're saying. Please try the following:

  • Use complete sentences, and don't write as if you would speak (it comes across as a stream of consciousness and is very hard to parse)

  • Use proper capitalization, punctuation, etc.

  • Look at your question from the perspective of someone who isn't you. You seem to make a lot of assumptions that I know what's going on with your game. Perhaps some screenshots, or more explanation, would help.

Also, remember that politeness goes a long way here. Acting indignant when your question isn't answered immediately won't get you any sympathy.

1 Reply

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

Answer by jahroy · Nov 11, 2011 at 09:02 PM

To literally do what you describe, you could use code like this:

function Update () { if ( Input.GetKey(KeyCode.W) ) { X = 10; Y = 0; }

 if ( Input.GetKey(KeyCode.D) ) {
     X = 5;
     Y = 5;
 }

}

However, as you suggest by saying using horizontal and vertical input, there are better ways to do it...

You could adjust X and Y based on Horizontal and Vertical input like this:

/* a variable used to control the speed */

var speedFactor : float = 0.002;

function Update () { if ( Input.GetAxis("Horizontal") != 0 ) { X += Input.GetAxis("Horizontal") * speedFactor; }

 if ( Input.GetAxis("Vertical") != 0 ) {
     Y += Input.GetAxis("Vertical") * speedFactor;
 }

}

The Horizontal and Vertical axes are mapped to the WASD keys, the arroy keys, and some other stuff. You can play with the input settings in the Inspector by choosing Edit -> Project Settings -> Input.

I recommend checking out the Input documentation and the camera control scripts that that come in the Standard Assets/Scripts folder.

There are also tons of questions and answers on this site about how to do stuff with character movement input (like clamp the values, smooth the motion, lerp the camera, etc...).

Hope this helps...

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

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

How to have vertical and horizontal axis work at the same time 1 Answer

Adapting Horizontal and Vertical movement to New Input System? 0 Answers

How can I make GUI button send an input message when I press it? 0 Answers

changing floats by input C# 1 Answer

Touch screen horizontal or vertical swipe 6 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