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 /
  • Help Room /
avatar image
0
Question by lemiwinks · Aug 06, 2013 at 11:40 PM · movecube

make objects slowly go up, then slam down

as the title says im looking for a way to make a cube shaped object slowly rise up, then slam back down. i know the basics to make it move forward and back, bit thats about it

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 robertbu · Aug 07, 2013 at 12:06 AM 0
Share

Is this just a visual thing or do you have physics involved somehow?

2 Replies

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

Answer by clunk47 · Aug 07, 2013 at 12:37 AM

Well you weren't too specific, so I'll just give you a basic tutorial on transform.Translate, in C-sharp, since you also didn't specify the language you want to use. This will still get you going.

 using UnityEngine;
 using System.Collections;
 
 public class Example : MonoBehaviour
 {
     float speed;
     Vector3 direction;
     float min;
     float max;
     float units = 2.0f;
 
     void Start()
     {
         //Set max to CURRENT position on Y axis, and set min to current minus units (2.0 in this example).
         max = transform.position.y;
         min = transform.position.y - units;
         
         //Set first direction to be down
         direction = Vector3.down;
     }
 
     void Update()
     {
         //Change speed depending on direction of object translation.
         if(direction == Vector3.down)
         {
             speed = 10.0f;
         }
         
         else if(direction == Vector3.up)
         {
             speed = 1.0f;
         }
         
         
         
         
         //Use transform.Translate to move the current direction and current speed.
         transform.Translate(direction * speed * Time.deltaTime);
         
         
         
         
         //Change direction if object has reached min or max position on the Y axis (up and down).
         if(transform.position.y >= max)
         {
             direction = Vector3.down;
         }
         
         if(transform.position.y <= min)
         {
             direction = Vector3.up;    
         }
     }
 }





Comment
Add comment · Show 3 · 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 lemiwinks · Aug 07, 2013 at 02:08 PM 2
Share

this is perfect the way it is :) thankyou!

ill try to be better next time and explain more, it was late and i was tired lol

avatar image clunk47 · Aug 07, 2013 at 04:23 PM 2
Share

I hear ye. Glad I could help.

avatar image pravinbudharap · Nov 30, 2015 at 06:55 AM 0
Share

thanks for the help me it really work good and i have one another question if i click the mouse cursor in the game at run time so an object will be down so how it is possible please give me a reply... and give a code of this question..

avatar image
0

Answer by gringofxs · Dec 24, 2016 at 11:40 PM

can i use this in vr.

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

17 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

Related Questions

Different jump height 1 Answer

What is the correct way to move objects relative to each other ? 1 Answer

Peculiar problem with frame-based bullets generator 0 Answers

How to move my 2D player up or down on the vertical axes depending on if it is facing up or down? 1 Answer

Blend generated fbx import to unity problem 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