Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 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
3
Question by Ziad · Jul 16, 2011 at 11:07 PM · c#animationdoor

How can I make the player collide with the door while the door is opening?

Well, I'm having a hard day with a door script, I finished the script and I made the door open after the user press E but while the door animation is playing the door isn't colliding with the player and I couldn't fix that :( and ideas?

Comment
Add comment · Show 4
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 aldonaletto · Jul 16, 2011 at 11:37 PM 0
Share

What's the door type? Sliding or hinged door?

avatar image Herman-Tulleken · Jul 16, 2011 at 11:38 PM 2
Share

http://answers.unity3d.com/questions/119077/how-do-i-make-animations-affect-physics-properly.html

avatar image Waz · Jul 17, 2011 at 12:46 PM 0
Share

@Herman Tulleken: that is an answer, not a comment. Please use the Answer section. (Sorry, couldn't resist, I needed an energiser from saying the reverse so often)

avatar image Herman-Tulleken · Jul 22, 2011 at 02:32 PM 0
Share

@Warwick Allison He he yeah... The link was a shortcut to indicate that I thought the question is sort of a dupe.

2 Replies

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

Answer by testure · Jul 17, 2011 at 08:06 PM

Either the door or your character needs a rigid body attached. If neither one has a rigid body, no collision will happen.

As a rule of thumb- if it moves and uses a collider/trigger, put a rigid body on it. If you don't need it to react to physics (which will usually be the case), set the rigid body to kinematic.

On a related note, triggers/colliders that move around require the physics engine to update the scene graph once per frame while the object is moving. This is a huge performance sink. If there's a rigid body attached, this does not happen.

Comment
Add comment · Show 2 · 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 Ziad · Jul 22, 2011 at 01:51 PM 0
Share

okey i've done that but still can make him stop after he hits the door, i mean , i want the player to stop and cant go through the door thats what i want :(

avatar image Reaper93 · May 12, 2019 at 03:42 PM 0
Share

I did not know that colliders that move without any rigidbody attached can be such a performance bummer. Thank you. I would have thought the opposite. Does it apply to Character Controller as well?

avatar image
1

Answer by Zergling103 · Jul 17, 2011 at 07:43 PM

Try coding your character and door movement around the physics engine.

First, make sure the door has a collider.

Second, add a rigidbody to the character's collider. Constrain it's rotation along the x and z axis. Change the collider's physics material to have no friction. Change it's drag to 10. Then the physics engine should move the character out of the way.

When moving around rigidbodies, it is best to use AddForce() or MovePosition() rather than moving the object using it's transform. So if in your code you wrote (in Update()):

 transform.position += moveVector;

Instead, write (in FixedUpdate()):

 rigidbody.AddForce(moveVector / time.deltaTime, ForceMode.Acceleration);

You can do a similar thing if you want the door to react to the player's presence. Add a rigidbody script to the door, use similar settings for Drag and Friction, and use AddTorque(0,rotationSpeed,0) to make it rotate.

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

8 People are following this question.

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

Related Questions

Open Door on Keypress Not Working - Animations 1 Answer

Stop box collider moving with object 1 Answer

Making an Animation pause function in a different game object 2 Answers

Multiple Cars not working 1 Answer

How to wait for animation completion (C#)? 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