Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 Sterilizen · Aug 14, 2013 at 03:54 PM · triggerdoor

Sliding Door question

I am trying to make a nice sliding door that opens on trigger enter and stops right below the surface, and closes on trigger exit and stops back at its original position. I decided to try using rigidbody.AddForce instead of using animation because I was running into an annoying mechanic.. Anyways, here's what I got:

 var door : GameObject;
 var speed : float = 20000.0;
 
 function OnTriggerEnter()
 {
     door.rigidbody.AddForce(Vector3.down * Time.deltaTime * speed);
 }
 
 function OnTriggerExit()
 {
     door.rigidbody.AddForce(Vector3.up * Time.deltaTime * speed);
 }
 
 function Update()
 {
     if(door.transform.position.y <= -2.5)
     {
         door.rigidbody.velocity = Vector3.zero;
         door.transform.position = Vector3(0, -2.55, 0);
     }
 }

The door opens smoothly and stops exactly where it should on enter, but when I exit, the door keeps going up.. past where I need it to be. This is my first script and I feel like i'm missing one tiny puzzle piece >.< lol

Comment
Add comment
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

2 Replies

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

Answer by Linus · Aug 14, 2013 at 04:00 PM

I think you have forgotten to stop it from going up. Just do as you did when stopping it from going down

if(door.transform.position.y >= xxxValueXXX)

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 Sterilizen · Aug 14, 2013 at 04:19 PM 0
Share

I could of sworn I tried that.. it works like a charm, thank you.

avatar image
0

Answer by Krahazik · Aug 29, 2017 at 01:12 AM

Therse seams to be an issue with the script or it is not complete as presented. I am getting a bunch of unexpected symbol errors for lines near the beginning of the script?

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

Sliding door animation question. 3 Answers

Door Opens When Not In Trigger And Sound Help 1 Answer

I am trying to make a door, when using this script nothing happens. 0 Answers

Multi Switch Door 4 Answers

Trigger Door Animation 2 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