Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 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 bromley · Jul 20, 2016 at 03:41 PM · animationcolliderpausedoorblock

Pause animation door when you block it while opens/closes

I created a door with 3 animations: Idle, Open and Close animation. When I interact with the door, it opens/closes, and if I do it while block its way, it pushes me. Then I want to create a script that pauses door animations when the player blockes it... and I can do it!

The problem is now: I want to create a script that pauses door animations ONLY IF the player hinds the opening/closing of the door. With the actual script, where I use OnTriggerEnter, if player touches the door, doesn't matter where it touches, the door animation pauses. But I want this only if the player touches the door towards the opening/closing.

I thought to use Collider.Raycast (because the door has a box collider), but i don't know how to distinguish the collisions from front or back of the door.

Comment
Add comment · Show 6
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 Cherno · Jul 20, 2016 at 04:20 PM 2
Share

Two ways to do this: 1. Add an animation event at the start of the opening/closing animation, and make it set a bool "transition" to true in the door script. Similarly, add another event at the end and amke it set the bool to false. Then, before stopping the door animation (by setting the animation speed to 0 or whatever), you first check if the door is transitioning 2. Similar to the above, but ins$$anonymous$$d of using a bool and events, check if the door's current anim state is opening or closing, and only then make it stop.

avatar image bromley Cherno · Jul 20, 2016 at 04:50 PM 0
Share

i have already done that, but the problem is another i want that door stops ONLY IF the player stay towards the way of the door

avatar image Cherno bromley · Jul 20, 2016 at 04:58 PM 0
Share

Well, can't you change the trigger shape and position then?

Show more comments

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Vollmondum · Jul 20, 2016 at 08:51 PM

You don't need animations etc. Unity people did everything for you.

Check this out:

https://docs.unity3d.com/Manual/class-HingeJoint.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
avatar image
0

Answer by bromley · Jul 20, 2016 at 06:43 PM

Now i created this script attached in a gameobject with a box collider, and this gameobject is child of the door

 using UnityEngine;
 using System.Collections;
 
 public class BlockDoor : MonoBehaviour {
 
     private Animation anim;
 
     private GameObject door;
 
     private Rotating_Normal_Door doorScript;
 
     void Start () 
     {
         door = transform.parent.gameObject; 
         anim = door.GetComponent<Animation> ();
         doorScript = door.GetComponent<Rotating_Normal_Door> ();
     }
 
     void OnTriggerStay (Collider col) 
     {
         if (col.gameObject.tag == "Player" && anim.isPlaying == true) 
         {
             foreach (AnimationState state in anim) 
             {
                 state.speed = 0.0F;
             }
         }
     }
 
     void OnTriggerExit (Collider col) 
     {
         if (col.gameObject.tag == "Player" && anim.isPlaying == true) 
         {
             foreach (AnimationState state in anim) 
             {
                 state.speed = 1.0F;
             }
         }
     }
 }

Works good but the door stops also when player touches it on the opposite direction.

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 bromley · Jul 20, 2016 at 07:26 PM 0
Share

$$anonymous$$AYBE SOLVED, look at this script

 using UnityEngine;
 using System.Collections;
 
 public class BlockDoor : $$anonymous$$onoBehaviour {
 
     private Animation anim;
 
     private Collider col;
 
     private GameObject door;
 
     private Rotating_Normal_Door doorScript;
 
     void Start () 
     {
         door = transform.parent.gameObject; 
         anim = door.GetComponent<Animation> ();
         doorScript = door.GetComponent<Rotating_Normal_Door> ();
         col = GetComponent<Collider> ();
     }
 
     void OnTriggerStay (Collider col) 
     {
         if (col.gameObject.tag == "Player" && anim.isPlaying == true) 
         {
             foreach (AnimationState state in anim) 
             {
                 state.speed = 0.0F;
             }
         }
     }
 
     void OnTriggerExit (Collider col) 
     {
         if (col.gameObject.tag == "Player" && anim.isPlaying == true) 
         {
             foreach (AnimationState state in anim) 
             {
                 state.speed = 1.0F;
             }
         }
     }
 
     void Update()
     {
         if (doorScript.open == true) 
         {
             transform.localPosition = new Vector3 (-1.0F, 0.0F, 0.0F); 
         }
         if (doorScript.open == false) 
         {
             transform.localPosition = new Vector3 (-1.0F, 0.2F, 0.0F);
         }
     }
 }

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

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

Related Questions

Triggering door animation with collider 2 Answers

Player to Door Collision and Animation 3 Answers

Raycasting fail 1 Answer

Box Collider not moving with animation 1 Answer

Open Door Via Trigger Collider 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