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 Count Swagula · Oct 14, 2014 at 07:59 PM · rigidbodytimerelevator

Unity 3d Elevator Script Not Working Properly

Hello all, I'm working on an elevator script that is built off of the lift example in the official tutorials. I want my elevator to move up and down, stopping for several seconds at the top and bottom for the player to walk in and out.

However, I cannot get the elevator to stop during the timer. What's more, the player falls through the elevator when he walks in. Can anyone give me any tips or answers?

Thanks

 using UnityEngine;
 using System.Collections;
 
 public class Elevator : MonoBehaviour
 {
         public float timeToDoorsClose = 1.4f;
         public Vector3 pointB;
         public float liftSpeed = 3f;
         private GameObject player;
         private bool playerInLift;
         private float timer;
 
         void Awake ()
         {
                 player = GameObject.FindWithTag ("Player");
 
     
         }
 
         IEnumerator Start ()
         {
                 var pointA = transform.position;
                 while (true) {
                         yield return StartCoroutine (MoveObject (transform, pointA, pointB, 3f));
                         yield return StartCoroutine (MoveObject (transform, pointB, pointA, 3f));
                 }
         }
     
         IEnumerator MoveObject (Transform thisTransform, Vector3 startPos, Vector3 endPos, float time)
         {
 
                 var i = 0.0f;
                 var rate = .05f / time;
                 while (i < 1.0f) {
                         i += Time.deltaTime * rate;
                         thisTransform.position = Vector3.Lerp (startPos, endPos, i);
                         //transform.Translate(endPos * liftSpeed * Time.deltaTime);
                         yield return null; 
                         //timer += Time.deltaTime;
                         
                         /*if (timer > 0) {
                                 thisTransform.position = endPos;
                         } else {
                                 thisTransform.position = startPos;
                         }*/
                 }
 
             
         }
 
         void Update ()
         {
 
                 if (playerInLift)
                         LiftActivation ();
 
                 
                 if (transform.position = pointB) {
                         
                         timer += Time.deltaTime;
                 } 
 
                 if (timer < timeToDoorsClose)
                         rigidbody.isKinematic = true;
                 else                
                         rigidbody.isKinematic = false;
         
                 
         }
 
         void OnTriggerEnter (Collider other)
         {
 
                 if (other.gameObject == player)
         
                         playerInLift = true;
         }
 
 /*        void OnTriggerEnter ()
         {
             timer += Time.deltaTime;
         }
 */
 /*        void OnTriggerExit (Collider other)
         {
 
                 if (other.gameObject == player) {
                         playerInLift = false;
                         timer = 0;
                 }
     }
 */    
         void LiftActivation ()
         {
 
                 player.transform.parent = transform;
             
             
                 //transform.Translate(Vector3.up * liftSpeed * Time.deltaTime);
             
             
         }
 }
 


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 Count Swagula · Oct 15, 2014 at 11:51 PM 0
Share

bump

I really need help so if just one person can push me in the right direction it would be of great assistance

0 Replies

· Add your reply
  • Sort: 

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

1 Person is following this question.

avatar image

Related Questions

Bullet Sometimes Go Throw Object 0 Answers

Putting variable into new Unity GUI InputField and then Acessing that variable 1 Answer

Elevator that parents player to itself causes jittery motion. 1 Answer

Rigidbody +parenting +rotation +elevator = Player unwanted behavior(pushed away) 1 Answer

Making a sped up timer in unity 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