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 Rxanadu · Aug 11, 2013 at 03:42 AM · time.deltatimesecondselevator

Moving elevator based on specified time limit

I'm trying to make an elevator move to a position based on the amount of time that's on an in-game clock. It's supposed to work similarly to a survival section in some games, where an elevator lift takes a specified amount of time to reach the bottom of a shaft.

As an example, I'll use a time limit of 30 seconds. If 5 seconds have passed, the platform will be 1/6 the way toward its final position; if 15 seconds pass, it will be halfway; after 30 seconds, the platform should be at its final destination.

I've tried setting the speed of the elevator's descent based on time rather than frames, but the speed is not consistent. Simply setting the speed to "(time limit) * Time.deltaTime" makes run faster the larger the time limit is; using the same equation but dividing the time limit by 60 (which I assumed would aid in making the time limit based on seconds) doesn't seem to work, either.

Any pointers on moving an elevator based on a specified time limit would be much appreciated.

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 cdrandin · Aug 11, 2013 at 03:49 AM 0
Share

you could use lerp to put it simply. Check the docs to see how it works. It scales with respect to time. From point A to point B

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Seth-Bergman · Aug 11, 2013 at 06:35 AM

Vector3.Lerp

basically you could say something like:

 var start : Vector3;
 var end : Vector3;
 var duration : int = 60;
 private var startTime: float;


 function Start(){
 start = GameObject.Find("Start Point").transform.position;
 end = GameObject.Find("End Point").transform.position;
 startTime = Time.time;
 }

 function Update(){
 var pos = (Time.time - startTime) / duration;
 transform.position = Vector3.Lerp(start,end,pos);
 }

something like this should do it (just tested, this works as desired)

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 Rxanadu · Aug 11, 2013 at 05:24 PM 0
Share

Unfortunately, the elevator travels too quickly for me to use as I intended. I did not specify this earlier, but I'm also using $$anonymous$$oveTowards() rather than Lerp(), as the latter tends to give me problems when moving one object to another position.

I just realized that by using Time.deltaTime, I am actually specifying how far an object will travel per second. I could use that to find out how long it would take to travel a specified amount of meters. Then, I could use that to ensure the elevator only travels at the correct speed to get to its destination by the end of the time limit.

avatar image Seth-Bergman · Aug 12, 2013 at 05:25 AM 0
Share

my script above works, just change "duration" to a larger number to decrease the speed.. notice the line:

 var pos = (Time.time - startTime) / duration;

(Time.time - startTime) is the elapsed time so far.. duration is the total time in seconds that the elevator will take to reach the end point.. Now, let's say we get the distance between start and end-point, that would simply be divided by duration to deter$$anonymous$$e the meters-per-second.. for example, if the total distance is 1000 meters, and the duration is 60, we know the speed of the elevator will be 1000/60, or 16 2/3 meters-per-second.

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

15 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

Related Questions

Spawn Randomly over Time 1 Answer

CountDown Timer Help (Seconds problem) 2 Answers

Take damage after seconds 3 Answers

Pause game while GUI instructions displayed? 1 Answer

Problem with elevator script (C#) 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