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 COLLAnitySV · Dec 12, 2011 at 02:43 PM · transformtranslatemoving platformelevatorlift

Elevator Script ?

how to make an elevator script that transform from target A to target B slowly but you need to activate the elevator by pressing [E] and then the elevator will going down and stop (when arrived at target B or target A). does anyone know how ?

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 Lo0NuhtiK · Dec 12, 2011 at 03:54 PM 0
Share

You can look through these two answers and see if they help you out.
ControllerCollider Falls Through or....
Ride an elevator?

4 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by Statement · Dec 12, 2011 at 05:22 PM

I guess by pressing E, you mean pressing E while looking at the elevator?

First, you should check if E is being pressed. If it is, make a raycast to interact with the elevator object. Upon interaction, translate the elevator toward one of the two transforms that indicate the two different floors.

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 Statement · Dec 12, 2011 at 05:56 PM 0
Share

If you'd want to puzzle in @OrangeLightning 's animation solution, you'd replace the translation with the animation ins$$anonymous$$d.

avatar image
1

Answer by FLASHDENMARK · Dec 12, 2011 at 05:35 PM

The best(and easiest) way would be to animate the elevator, either using Unity's animation panel or animate it using your favorite 3d app. Now assuming you have animated the elevator, lets get scripting.

 var isAtOriginalPosition = true; //Variable to control if the elevator is "up" or "down" 
 
     function Update(){
         if(Input.GetKeyDown("e")){
             ActiveElevator();
         }
     }
     
     function ActiveElevator(){
         if(isAtOriginalPosition){
             animation["animationName"].time = 0;
             animation["animationName"].speed = 1;
             animation.Play("animationName");
             isAtOriginalPosition = false;
         }
         else{
             animation["animationName"].time = animation["animationName"].length;
             animation["animationName"].speed = -1;
             animation.Play("animationName");
             isAtOriginalPosition = true;
         }
     }



This is a script controlling where the position of the elevator is. It is very basic and works. HOWEVER this script is lacking something, you will properly notice the limitations of the code I enclosed(the code is not intended to cover every aspect or problem, etc. but merely a demonstration.).

I will strongly recommend animating the object, and use scripts to activate it. However if you want to use code only you could use something like Mathf.Lerp to 'Lerp' the position to where you want it.

EDIT: If you want to make better use of code without using animations listen to Statement.

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 Statement · Dec 12, 2011 at 05:54 PM 0
Share

Animations are almost always to be preferred, since they can add much more motion details and are easier to tweak. The exception would be a quick-and-dirty solution for a small project or settling with the rather static effect that Vector3.$$anonymous$$oveTowards or Vector3.SmoothDamp can offer. +1

avatar image
0

Answer by sexyetoe · Dec 16, 2011 at 09:54 AM

it's very usefull

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
avatar image
0

Answer by josprachi · Feb 27, 2019 at 11:41 AM

A ready example might help [elivator example][1]https://crackpracgameshowcase.blogspot.com/p/creating-a.html

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

8 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Dont transform.translate if it will collide with another object 1 Answer

How can I instantiate and move objects smoothly? 1 Answer

transform.Translate not translating in relation to rotation 0 Answers

Simultaneously translating and rotating 2D sprite? 1 Answer

How to wait until player move to a specific position 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