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
3
Question by pepperedereppep · Nov 11, 2010 at 02:15 PM · transformsmoothverticalhorizontal

alternative to using horizontal/vertical

Just a quick question. How would you code something that would have the same effect as this code, with the smoothing at the end and everything, but without using the horizontal/vertical and without using physics? (using the a and d keys)

function Update ()
{
    transform.Translate (Input.GetAxis ("Horizontal"), 0, 0);
}

Thanks!

more info as requested :)

Yes, I want to translate an object based on a button input, but smoothed out.. I want to know how the code works so I can try to apply it to other things, like, smooth scale in/out based on holding the left/right button, or smooth offset a texture based on how long I hold a button, etc.

Thanks!

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 Herman-Tulleken · Nov 11, 2010 at 02:33 PM 0
Share

Could you explain exactly what you want to do in a bit more detail? For example, do you want to translate an object based on a button input, but smoothed out?

avatar image pepperedereppep · Nov 11, 2010 at 03:42 PM 0
Share

Yes. :), that's basically what I want I guess.

1 Reply

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

Answer by Mike 3 · Nov 11, 2010 at 03:42 PM

You'd use something along the lines of this:

var speed : float = 3; //just to make it a lil more configurable

function Update () { var horizontal = 0; if (Input.GetKey(KeyCode.A)) horizontal = -1; if (Input.GetKey(KeyCode.D)) horizontal += 1; transform.Translate (horizontal speed Time.deltaTime, 0, 0); }

With smoothing:

var speed : float = 3; //just to make it a lil more configurable var currentHorizontal : float = 0;

function Update () { var horizontal = 0; if (Input.GetKey(KeyCode.A)) horizontal = -1; if (Input.GetKey(KeyCode.D)) horizontal += 1; currentHorizontal = Mathf.Lerp(currentHorizontal, horizontal, Time.deltaTime); transform.Translate (currentHorizontal speed Time.deltaTime, 0, 0); }

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 robertmathew · Mar 25, 2011 at 10:31 AM 0
Share

can you please explain how this will work what does horizontal = -1, and horizontal +=1 works

avatar image Mike 3 · Mar 25, 2011 at 11:01 AM 0
Share

it's just an int, when used in translate as x, -1 goes left, +1 goes right

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

No one has followed this question yet.

Related Questions

Trying to make character move like frogger 0 Answers

gameobject translation problem 2 Answers

Don't know why checking if not something stops the whole thing working 1 Answer

get euler rotation from horizontal and vertical axis values 1 Answer

Smooth look at Random Transform ? 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