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
1
Question by AndreasX12 · Nov 10, 2012 at 02:21 PM · objectmoveupdown

"Hover" object up and down

Hello, Is it possible to make a script that smoothly moves an object up and after a few seconds down again?

Thanks, Andreas.

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 Kmulla · Nov 10, 2012 at 07:49 PM 0
Share

It is possible :) An easy solution would be using iTween (http://itween.pixelplacement.com)

avatar image AndreasX12 · Nov 10, 2012 at 08:27 PM 0
Share

Thank you :D Just what I was looking for :D

2 Replies

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

Answer by o_oll · Nov 11, 2012 at 05:33 AM

A really quick and dirty way to achieve this would be to just move the objects y axis along a sine curve. I.e.:

         var Step : float; //A variable we increment
         var Offset : float; //How far to offset the object upwards
         
         function Start () {
         //Store where we were placed in the editor
         var InitialPosition = transform.position;
         //Create an offset based on our height
         Offset = transform.position.y + transform.localScale.y;
         }
         
         function FixedUpdate () {
         
         Step +=0.01;
           //Make sure Steps value never gets too out of hand 
           if(Step > 999999){Step = 1;}
 
           //Float up and down along the y axis, 
           transform.position.y = Mathf.Sin(Step)+Offset;
         }
 
 
Comment
Add comment · Show 1 · 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 Civita_88 · Jul 29, 2016 at 05:18 AM 0
Share

any idea how to increase the size of the sine curve so the object moves up higher and moves down lower?

avatar image
0

Answer by FakeBerenger · Nov 10, 2012 at 10:41 PM

Easier than iTween (Not that is particularly hard ...), there is still Mathf.Lerp / Vector3.Lerp.

Oh, and checkout that link if you want to continue with iTween : http://wiki.unity3d.com/index.php?title=ITweenX

Comment
Add comment · Show 1 · 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 AndreasX12 · Nov 11, 2012 at 07:52 AM 0
Share

Thanks :-)

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

13 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

Related Questions

Move up and down one arm 1 Answer

Slowly speed something up to a top speed after a specified amount of time? 0 Answers

How can i move a game object up and down so it acts like a obstacle for my sphere player 4 Answers

How should I move an object that parents on collision? 1 Answer

using Transform on a Object will not move it 100% exactly... 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