x


Parenting On Trigger not Working?

Hey Everybody! So I have a Ship that has a Box Collider inside it. When My player collides with the Collider, it activates an AI Script. What I was trying to do was that at the same time, have the Player Made a Child of the Ship So that it goes wherever the AI goes, until nessecary. So therefore the Player needs to be Inactive for a variable amount of time. I was using this script but instead of getting parented, the player just goes flying off the edge! Is there a different script that I should use?

UPDATE! I FINALLY FIGURED IT OUT:

var scriptname1 : GameObject;

function OnTriggerEnter(other: Collider)

{

if(other.tag == "Player")

{

scriptname1.active = false;

   other.transform.parent = transform.parent; 

}

}

function Update () {

if (Input.GetKeyDown ("e")){

Destroy(gameObject);

scriptname1.active = true;

}

}

Thanks for all your help!

more ▼

asked Aug 08 '12 at 11:28 PM

sketchers1 gravatar image

sketchers1
169 14 20 28

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

3 answers: sort voted first

Here is the mostly Correct Script, the one thing I cannot figure out is getting out of the ship.

var scriptname1 : GameObject;

function OnTriggerEnter(other: Collider)

{

if(other.tag == "Player")

{

scriptname1.active = false;

   other.transform.parent = transform.parent; 

}

}

function Update () {

if (Input.GetKeyDown ("e")){

Destroy(gameObject);

scriptname1.active = true;

}

}

more ▼

answered Aug 09 '12 at 03:24 AM

sketchers1 gravatar image

sketchers1
169 14 20 28

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

Not sure but wouldn't "col.transform.parent = transform.parent;" just be "col.transform.parent = transform;"?

more ▼

answered Aug 09 '12 at 12:30 AM

cassius gravatar image

cassius
92 6 8 12

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

hallo, I use this, found somewhere here, on a trigger inside the lift

var platform : Transform;
var player : Transform;

function OnTriggerEnter () {
   player.parent = platform;
}

and this on a trigger just when exit the lift

var platform : Transform;
var player : Transform;


function OnTriggerEnter () {
  player.transform.parent = null;

}

using OnTrigerExit on the trigger is in the lift don't know why, but don't work

more ▼

answered Aug 09 '12 at 12:49 AM

Ingen gravatar image

Ingen
145 3 11 19

I saw that source earlier and tried modifying it to fit my needs, but that would not work either.. Thanks Though!

Aug 09 '12 at 12:51 AM sketchers1
(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:

x983
x422
x410
x335
x32

asked: Aug 08 '12 at 11:28 PM

Seen: 375 times

Last Updated: Aug 09 '12 at 01:10 PM