x


Teleport Charactor

I am needing a code that when you collide with an invisable collide i have placed in the doors. I want it so that each door of my building has a invisable collider in it and depending on wich u collide with you go inside to the other side of that door. All my inside and out are in one scene.

more ▼

asked Apr 15 '12 at 01:16 AM

Davidflynn gravatar image

Davidflynn
61 22 49 55

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

2 answers: sort voted first

It sounds to me as though you want to have a collider defined as a trigger and when the trigger throws an event, you detect that event and change the position of the character that caused the trigger to be a new position corresponding to "inside door". The core concepts of this answer are:

  • Triggers
  • Collider.OnTriggerEnter
  • Transform.position
more ▼

answered Apr 15 '12 at 01:29 AM

kolban gravatar image

kolban
1.8k 2 7

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

ok what you can do is set an emptyGameObject in each of the sides of the door(where the player will "teleport"once the collider is activated)..and add this script to the empty game objects.

second add another 2 empty game objects and place them a little appart from the other 1s so its like if u have 2 emtygameobjects on each side .....add this script to 1 emty on each side ...and a collision box ..set the collision box to "trigger"...and fill in the "destination" variable by draging the oposite empty into there ...so emty is 2 collided and the other to teleport from the opposite side.....

var destination: Transform; // drag the destination object here
var teleportSound: AudioClip; // set this to the teleport sound, if any

function OnTriggerEnter(col: Collider){
    col.transform.position = destination.position; // teleports object
    col.transform.rotation = destination.rotation; // makes it face the correct side
    if (teleportSound){ // plays the sound effect at the destination
        AudioSource.PlayClipAtPoint(teleportSound, destination.position);
    }
} 
more ▼

answered Apr 15 '12 at 01:41 AM

darkcookie gravatar image

darkcookie
294 16 25 32

(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:

x255
x11

asked: Apr 15 '12 at 01:16 AM

Seen: 401 times

Last Updated: Apr 15 '12 at 01:41 AM