Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 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 Oxidor · Jul 10, 2013 at 08:45 PM · animation3dsmaxdoors

open a animated door

Hi i have some probleme with animation in unity :s I do a animation of a door in 3ds max. I export my door in fbx and i import this one in unity. Now i don't even understand how launch the animation of the door. I can see my animation on preview (inspector) but nothing on my "game window".

My purpose is when i approche the door with my first person controller and I press a key, the animation of the door start. How can i do that?

Thanks in advance

PS: sorry for my english =s

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

3 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Wettechsupport · Jul 10, 2013 at 09:40 PM

Well, if you animate the door in 3DS Max, it won't animate physics (or it may, but it would run slowly)

I'm a beginner myself, but what I suggest... Make the model's origin on the door hinges, then rotate it in the script using transform.Rotate. You might want to disable to colliders while it's moving though.

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 Oxidor · Jul 10, 2013 at 10:02 PM 0
Share

hi, it's a animation of 2 sliding door (like a elevator) it's old door, so it's un little bit complicated animation. I find this http://www.youtube.com/watch?v=ZTTULr$$anonymous$$GVQI but can't import the animation like him, don't have the same inspector content :s I can't even import a animation :s

avatar image
0

Answer by rowdyp · Jul 10, 2013 at 10:18 PM

well the first step is to probably add a collider on the door and make it a trigger by clicking the is trigger box. Then move the collider where you want it in correlation to the door. Next, add a script to the door that has the key press and and the plays the animation. Something like

 function OnTriggerEnter (other : Collider) 
 {
         
 if (Input.GetKeyDown ("space"))
            animation.Play("opendoor");
 }

forgive layout or possible errors in my code, I am on my phone.

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 programer717 · Nov 11, 2018 at 09:07 PM 0
Share

Hi, just confused but wouldn't this make it impossible to duplicate the door with Ctrl D?

avatar image
0

Answer by Oxidor · Jul 10, 2013 at 11:58 PM

OMG !!! that's work... but don't really know how it's work....i take a script found on the net, i put the rig of the door on legacy and it's work... This is the script:

 var DoorGameObject : Transform; // This is a reference to the door GameObject that has your animation
 private var HasTriggerBeenUsed : boolean = false; // This is to make sure that the button is not repeatedly pressed.
 private var setTrigger : boolean = false;
 function OnTriggerStay() {
    if (Input.GetKeyDown("e") && !HasTriggerBeenUsed) {
       DoorGameObject.animation.Play("Take 001");
       setTrigger = true;
    }
    else if (Input.GetKeyDown("e") && HasTriggerBeenUsed) {
       DoorGameObject.animation.Play("Take 001"); // Insert name of DoorClose animation instead of that
       setTrigger = true;
    }
    if (setTrigger) { HasTriggerBeenUsed = !HasTriggerBeenUsed; }
 }

   

Now i would like to play a sound when i launch the animation, how can i do this? thx in advance (and thx for your answer rowdyp )

Comment
Add comment · Show 6 · 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 rowdyp · Jul 11, 2013 at 05:23 PM 0
Share

use an animation event, first you have to duplicate the animation then drag the duplicated animation on the door in the scene. Then create a script to play animation with something like

 var soundPlayer : AudioSource;
 var opensound : AudioClip;
 var Door : Gameobject
 
 function playSound()
 {
   soundPlayer.audio.clip = opensound;
   Door.audio.Play();
 }

Drag the door object into door(duh) make sure your door has an audiosource attached to in and place it in the appropriate variable, do the same for the sound. Place this script on the door. Then go to Window>Animation in Unity, find the frame where you want to play the sound, right click then add Animation Event(), then select the appropriate function which was playSound() from the drop box. If you want a closing sound, just make a variable for the closing sound and create another function to play that sound, add another animation event for the closing door sound at the right frame.

avatar image Oxidor · Jul 11, 2013 at 08:21 PM 0
Share

Thank you for your answer I m a beginner in scripting and don't really understand your script. It's not just possible to start a sound when i press "E" ("E" launch my animation) only if i'm in the trigger?

avatar image rowdyp · Jul 11, 2013 at 09:11 PM 0
Share

not well yeah you could, but it may not sync up correctly depending on the audio clip, ect. Basically the first three lines create the variables in the inspector to which you can drag and drop the audio player (audiosource) attached to the door, the door itself, and the sound effect. The rest is just telling the audiosource what to play and when. If you want to just play the audio clip when you press the button, just open the script that plays the animation and add this

 var opensound : AudioClip;
  
 if (Input.Get$$anonymous$$eyDown ("e"))
 {
 audio.Play("opensound");
 }

then just drag the sound effect into the opensound slot created in the inspector

avatar image jovino · Jul 11, 2013 at 09:12 PM 0
Share

Yes, you can start the sound without the trigger. The trigger thing is for make the door open only when in range.

avatar image Oxidor · Jul 11, 2013 at 09:29 PM 0
Share

i want activate the sound only when I'm in the trigger (don't want a door sound if i press E and i m not near my door) I just want add some line to my script to start a sound when my animation start and I'm in the trigger. But i don't know what i must add and where. But i will try to understand your first answer if you have no more proposition

Show more comments

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

19 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

Related Questions

Character controller problem? 2 Answers

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

help in animation/code 1 Answer

How to correct the First Person Controller orientation when parenting to a rotated x.270 degrees model? 2 Answers

Can you fix my code? (Audio for doors) 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