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 Creepercatss · Mar 30, 2017 at 05:02 AM · programmingvector3.lerpgeneral programminggeneralhealth

General programming question C# Unity

Hello everyone! I had a question that i kept asking myself and could never figure a proper way to do this.

What i want to happen is something like this.

-User presses key once – An object moves from one spot to another using Vector3.Lerp Vector3.Lerp requires it to be repeated either in the update method or some other way. I was wondering what the most efficient way i could make this happen with just one button press and not have to hold down the button.

Thanks in advance to everyone! Happy developing!

Comment
Add comment · Show 1
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 hexagonius · Mar 30, 2017 at 06:54 AM 0
Share

for lerp you need to calculate the alpha. when you use $$anonymous$$ovePosition you just use the speed as last parameter, so that's easier.
furthermore, just change the target position on press and just run $$anonymous$$ovePosition in Update. if target is the same position at the beginning as the object's, it won't move. as soon as target changes, it moves there. this makes it easy to just set different target positions.

1 Reply

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

Answer by SohailBukhari · Mar 30, 2017 at 08:35 AM

@username

if you don't want to move in update or not want to press the button to move,then there is a simple way of moving object.

  1. Make a thread to move object.

  2. Make Two points to move from one point to other.

  3. Time For moving object to destination.

class MyClass: MonoBehaviour {

          [SerializeField]private Vector3 _pointBVector3;
      
          private void Start()
          {
              var pointAVector3 = this.transform.position;
              StartCoroutine(MoveObject(this.transform,pointAVector3,_pointBVector3,Random.Range(2f,5f)));
          }
          /// <summary>
          /// MoveObject
          /// </summary>
          /// <param name="_transform">Pass transform Which You Want To Move</param>
          /// <param name="initialPos">Start Position Of Move Object</param>
          /// <param name="endPos">PointB </param>
          /// <param name="time">Random Time Like Random.Range(2f,5f)</param>
          /// <returns></returns>
          private IEnumerator MoveObject(Transform _transform,Vector3 initialPos,Vector3 endPos,float time)
          {
              var i = 0.0f;
              float rate = 1.0f / time;
              while (i < 1.0f)
              {
                  i += Time.deltaTime * rate;
                  _transform.position = Vector3.Lerp(a: initialPos, b: endPos, t: i);
                  yield return null;
              }
          }
      }



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.

Follow this Question

Answers Answers and Comments

102 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 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

Change the color of material based on percentage of health remaining 1 Answer

fixing rpc 0 Answers

Speeding up load time 0 Answers

adding two integers together once every half second,adding two integers together with delay? 1 Answer

XBox one controller only returning -1 or 1 for right analog stick. 0 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