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 youngapprentice · Nov 12, 2012 at 05:35 PM · movementlerpsimple

Lerp movement speed

Hello, all! I have a ship that moves up, left, right, and down using this script:

 var moveSpeed : float = 5.0;
 
 function Update (){
     
     var x = Input.GetAxis("Horizontal") * Time.deltaTime * moveSpeed;
     var y = Input.GetAxis("Vertical") * Time.deltaTime * moveSpeed;
     
     transform.Translate(x, y, 0, Space.World);
     
 }

Simple stuff, right? Well I was wondering if there was a way for me to lerp the movement speed on each key press. For instance, when I hit the up key (When GetAxis"Vertical" == 1), the movement speed starts off slow, and builds up over a set float variable (number of seconds) to the target moveSpeed, and when the key is released, the same thing occurs, except backwards.

This would create a very nie 'sliding' kind of effect that I think would be appropriate for a space scene.

Thanks! - YA

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by markpdolby · Nov 12, 2012 at 05:55 PM

 var maxSpeed = 10;
 var x = 0;
 
 function Update(){
 if(Input.GetAxis("Horizontal") == 1)
 {
     x = Mathf.Lerp(x, maxSpeed, Input.GetAxis("Horizontal") * Time.deltaTime * moveSpeed);
 }
 else
 {
     x = Mathf.Lerp(x, 0, Input.GetAxis("Horizontal") * Time.deltaTime * moveSpeed);
 }
 //Then the same for Y etc.
 }

Something along those lines should point you in the right direction. Hope that helps.

Comment
Add comment · Show 6 · 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 youngapprentice · Nov 12, 2012 at 05:59 PM 0
Share

That looks pretty good. I'll get back to you on how it works out.

avatar image youngapprentice · Nov 12, 2012 at 06:12 PM 0
Share

No... There's definitely something missing from here

avatar image markpdolby · Nov 12, 2012 at 06:18 PM 0
Share

What happens?

avatar image youngapprentice · Nov 12, 2012 at 06:25 PM 0
Share

I mean, besides the obvious "moveSpeed" variable and the actual Translation call.

Well, I hit the key, and the ship moves... I can't quite tell if it's lerping or not (I assume it must be).

What's missing is a Dampen variable. I'd like to have direct control over how much time it takes to accelerate/decelerate.

Also, the ship moves EXTRE$$anonymous$$ELY quickly

How is this working with the keys? I didn't know Input.GetAxis() could return anything but 1/0!

avatar image youngapprentice · Nov 12, 2012 at 07:10 PM 0
Share

Also, I would like to know how I would get this to function for moving the ship Downwards or left.

Show more comments

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

How to lerp over time help? 1 Answer

Wait a fraction of a second within a Function Update() 1 Answer

rotate object by list values 0 Answers

My code break character controller 2 Answers

Changing Color Based on Z position 2 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