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 LegibleMushroom · Aug 20, 2012 at 02:17 AM · animationjavascriptraycastcolliderdoor

Raycasting fail

Hello. I'm attempting to create a semi-complex door animation to activate when my characters raycast hits it, then it opens, and either:

Whilst the animation is happening it destroys the door's collider to prevent any possible glitches or replaying the animation when the raycast hits it

Or

Destory the door (it sinks into the floor, walls and roof) once the animation is over (so a timed function I guess)

Here's what I have so far

 var rayCastLength = 10;
 
 function Update()
 {
     var hit : RaycastHit;
 
     //check if character is colliding with door
     if(Physics.Raycast(transform.position,transform.forward,hit,rayCastLength))
     {
        //with the character
        if(hit.collider.gameObject.tag == "door")
        {
          //open the door
          hit.collider.gameObject.animation.Play("Take 001");
          //destroy the door's collider
          Destroy(hit.collider.gameObject);
        }
     }
 }

Thanks in advance for any and all replies :D

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 sparkzbarca · Aug 20, 2012 at 06:20 AM 0
Share

what exactly is the problem? are you asking how to make the animation or the code to trigger it? also I don't think you'd need to destroy the collider, you could simply do collider.enabled = false That will prevent it from interacting with other colliders.

is that what you want to do? (also i'd do the collider.enabled = false $$anonymous$$ to the play animation not after you already started so the begining doesn't wonk it up)

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by LegibleMushroom · Aug 20, 2012 at 09:00 AM

Alright, I eventually got it working.. 2 minutes ago.. Haha I didn't know about a collider.enabled >.< Here's my final code for anybody that has a similar problem

 var rayCastLength = 10;
 
 function Update()
 {
     var hit : RaycastHit;
 
     //check if character is colliding with door
     if(Physics.Raycast(transform.position,transform.forward,hit,rayCastLength))
     {
        //with the character
        if(hit.collider.gameObject.tag == "door")
         {
             //open the door
             hit.collider.gameObject.animation.Play("Take 001");
             //destroy the door
             Destroy(hit.collider.gameObject,3);
         }
     }
 }

What I had was an animation I created in 3DS Max along with the door itself, the animation was playing correctly and all, but all I needed was to be able to destroy either the door or the doors collider so I can walk through where the door was.

Thanks anyways :)

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

9 People are following this question.

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

Related Questions

If an specifc animation is playing dont let other animations play. 1 Answer

Playing Different Animation Troubles 0 Answers

Start Animation in code is not working 1 Answer

Player to Door Collision and Animation 3 Answers

Animation Script not working. 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