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 Garneth101 · Dec 09, 2012 at 03:23 AM · c#movementcontinuous

I want my vehicle to keep moving left/right while the buttons are held down?

I want to make it so that my vehicle can move left and right more than just once (currently, it only moves once each time the button is hit. I want it to keep moving while the button is held down, to make the movement more fluid). Here's my current script for the vehicle (C#):

 using UnityEngine;
 using System.Collections;
 
 public class playerScript : MonoBehaviour {
     
     float vehicleSpeedLeftRight = 10f;
     float vehicleSpeed = 10f;
     // Use this for initialization
     void Start () {
     
     }
     
     // Update is called once per frame
     void Update () {
         if (Input.GetButtonDown ("Horizontal") )
         {
         transform.Translate( vehicleSpeedLeftRight * Time.deltaTime * Input.GetAxis( "Horizontal" ), 0, 0 );
         }
     }
     
     void FixedUpdate()
     {
         rigidbody.AddForce(-transform.forward * vehicleSpeed, ForceMode.VelocityChange);
         rigidbody.velocity = -transform.forward * vehicleSpeed;
     }
 }

(The reason there's a negative sign next to the transform.forward is because for some reason it was going backwards instead of forwards, so I used that to make it un-inverted)

Comment
Add comment · Show 4
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 AlucardJay · Dec 09, 2012 at 03:28 AM 0
Share
 Input.GetButton

http://docs.unity3d.com/Documentation/ScriptReference/Input.GetButton.html

avatar image Garneth101 · Dec 09, 2012 at 03:34 AM 0
Share

Thank you; that works! :)

avatar image AlucardJay · Dec 09, 2012 at 03:43 AM 0
Share

No worries, the Unity Scripting Reference is useful for finding commands or how to use them, just use the search bar in the top-left.

Input (scroll down to class functions) : http://docs.unity3d.com/Documentation/ScriptReference/Input.html

avatar image Garneth101 · Dec 09, 2012 at 03:47 AM 0
Share

Oh that really helps! Thank you so much :)

1 Reply

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

Answer by shane.rachel · Dec 09, 2012 at 03:41 AM

Input.GetButtonDown only passes true when you press down the button. Input.GetButton passes true the entire time you hold down the button.

Comment
Add comment · Show 5 · 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 Garneth101 · Dec 09, 2012 at 03:42 AM 0
Share

Thank you so much! :)

avatar image shane.rachel · Dec 09, 2012 at 03:57 AM 0
Share

your welcome, alucardj already answered it but I figured I would explain the difference, they're both useful in different situations.

if you thought they were useful you should up vote me :)

avatar image Garneth101 · Dec 09, 2012 at 03:59 AM 0
Share

I tried to upvote you but it said I can't lol. Not sure why

avatar image shane.rachel · Dec 09, 2012 at 04:25 AM 0
Share

hmmmm lol well that's too bad, maybe it;s just isn't saying you did but you actually did.

avatar image AlucardJay · Dec 09, 2012 at 05:08 AM 0
Share

you need 15+ karma from memory to upvote an answer on any question. When answer is accepted, you both also gain karma.

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

11 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

Related Questions

Making a bubble level (not a game but work tool) 1 Answer

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

Separate Objects after Mouse Clicking in Unity 5.6.4 1 Answer

How to move along a few path follow ? 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