x


Opening a door at proximity

Hi. I would like a door that opens as soon as the player get's close enough (no need to press any button). The player is a Standard Asset prefab for an FPS. To door would open vertically and go up as soon as the player get's close to it. Thanks

more ▼

asked Nov 02 '10 at 03:32 PM

Antonios gravatar image

Antonios
9 8 8 13

(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

Set up an empty game object in front of the door, make the collider a trigger, and attach an OnTriggerEnter code on it. Compare the tag of the collider and if it's "Player" tag, have the animation play and the door open.

more ▼

answered Nov 02 '10 at 03:36 PM

Persona gravatar image

Persona
246 74 85 96

How do I make the animation?

Nov 03 '10 at 11:21 AM Antonios

Antonios, you could for example make a script that would slowly raise the door a certain amount. Then perhaps do the opposite on OnTriggerExit.

Nov 03 '10 at 02:58 PM Matti Jalopeura

My animation makes the door Open and Close directly, how do I split the animations? I made them with unity so they do not appear on the FBXimporter...

Nov 04 '10 at 01:52 PM Antonios
(comments are locked)
10|3000 characters needed characters left

HI....although a newbie to both Unity and scripting...i found this using Raycast, just make sure your door has a collider and Is Trigger is off....

var RayCastlenght = 2; //allows you to change the distance required to trigger the door

function update() { var hit : RaycastHit;

    //check if we are colliding
    if(Physics.Raycast(transform.position, transform.forward, hit, RayCastlenght))
    {
        //...check colliding with door
        if(hit.collider.gameObject.tag == "BookCase")
        {

            //move the case
            hit.collider.gameObject.animation.Play("BookCase_anim");
        }
    }
}

what you need to do is compose an animation for the door to open and then change Bookcase_anim with your new animation.....

best of luck

more ▼

answered Nov 13 '10 at 12:00 PM

MohdGasim gravatar image

MohdGasim
33 5 5 9

Thanks, this helped^^

Nov 16 '10 at 01:01 PM Antonios
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

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

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x1282
x1095
x810
x500
x35

asked: Nov 02 '10 at 03:32 PM

Seen: 1591 times

Last Updated: Nov 02 '10 at 03:32 PM