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 DevMerlin · Feb 04, 2012 at 07:23 AM · c#animationraycastvector3raycasthit

Door only opening once on Raycast

I'm trying to get a door to open properly - using an animation, from both directions. At the moment, I've gotten it to open going one direction, but then it refuses to open again from the other. The script is very simple:

         RaycastHit hit;
     if (Physics.Raycast(transform.position, Vector3.forward, out hit, 2.0F))
     {
         hitObject = hit.transform.parent;
         
         
         string objectName = hitObject.name;
         
         

         switch (objectName)
         {
             case "door_and_Frame":
                 hitObject.animation.Play("Take 001");
             break;    
         }
         
     }  

Is there any recommended way to reset the raycast - or object, so that it detects it again coming through the door a second time or in the opposite direction?

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Aram-Azhari · Feb 04, 2012 at 09:04 AM

If you are trying to open the door by getting close to it, then you should use colliders/triggers.

Physics.RayCast is usually used to detect the presence of an object in front of the ray.

But in you current case, after you open the door once, try to get away from the door with a long distance without looking at it. Then come back and see if it triggers again.

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 DevMerlin · Feb 04, 2012 at 09:58 AM 0
Share

No go. Even through a door thath hasn't been opened yet and back again... and it does the same thing. The second door opens... and then locks you out.

avatar image Aram-Azhari · Feb 04, 2012 at 10:07 AM 0
Share

I assume the code is on the player object. On which event are you using these code?

avatar image DevMerlin · Feb 04, 2012 at 10:34 AM 0
Share

Update() C#, with the code placed on the player camera. I did some research before posting this and it seems that it only hits each object once.. and then does not reset for that object. The script is ment for interaction with other objects as well, not just doors which is why raycast was used.

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

C# raycast shooting script broken 1 Answer

C# - Trigger Animation with Raycasting? 1 Answer

Another Raycast Issue. 0 Answers

Need some help with to grap .x with a Raycasthit (c#) 1 Answer

Raycasting Help 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