Jump to content
This site uses cookies! Learn More

This site uses cookies!

armedunity.com uses cookies to improve user experience.

By continuing to use this site, you agree to allow us to store cookies on your computer.

  • 0
themars2011

Doors with collision detection

Question

Hey guys,

 

I want to make some doors that have collision detection like in the source engine, where the door would not continue to rotate when something (e.g. a player) is in the way and not clip through him.

Any ideas how to go about that? I was thinking of a rigidbody, but I am not exactly sure how I would make it rotate to a specific rotation.

Share this post


Link to post
Share on other sites

5 answers to this question

Recommended Posts

  • 1

i think "OnCollisionEnter()" is ment for that. 

Docs: Please login or register to see this link.

 

So would just do sth. like: 

bool bIsRotating = false;

 

void Rotate(){

       while(bIsRotating){

               //rotate(open door)

       }

}

 

void OnCollisionEnter(/*i think it takes some args just put em in here*/){

    bIsRotating = false; 

}

 

Yeah... sth. like that. 

I believe leaving it like that could cause some problems but it should give you a general idea. 

 

In the actual game i think it would be a good idea to have 2 colliders. One for the inside and one for the outside of the door, that way the player opening the door and pushing against it wont stop the rotation of the door but sth. hiting the outside of the door would. 

 

Dont know if this was helpful or not... but that would be a really fast n simple turn to it 

Share this post


Link to post
Share on other sites
  • 0
Please login or register to see this quote.


How about a raycast or linecast on the skinned mesh part? I guess you'd just stop and play the animation on and off based on collision detection?

Share this post


Link to post
Share on other sites
  • 0

Didn't try yet but I think that will be to late at that point because they already collided? I'll see

Share this post


Link to post
Share on other sites
  • 0
Please login or register to see this quote.

if you want it to stop before the collision actually happens you can do the sam thing, just move the colliders a bit, so they are sligtly bigger than the door and make them triggers and use "OnTriggerEnter()" instead. 

but it would actually come down to the same thing you wont notice any difference in the actual game 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×