Moving platform (85327)

Hi there i am trying to make a moving platform that will start to move when the player is on the trigger, i got a working trigger but i can make the platform move. i started with this code but i have absolutely no idea how continue it, please help!!!

var platform : Transform;

function OnTriggerEnter(col: Collider)

{

if(col.tag == “Player”)

{

   col.transform.parent = transform.parent; 
}

}

function OnTriggerExit(col: Collider)

{

if(col.tag == "Player")
{
   col.transform.parent = null; 
}

}

3 Answers

3

Try parenting the platform to the player, instead of the player to the platform. Then, the platform will move with the player when you use the player controls.

If this isn’t the the behavior you want, then leave a comment on this answer and provide more info on what exactly you want the platform to do.

Basicly I need that the platform moves when the player is on it and stays on it while moving from A to B; in case the player jumps off the platform this just stops.

–

try this:

var platform : Transform;

function OnTriggerEnter(col: Collider)

{

if(col.tag == "Player")

{

   col.transform.parent = null; 
}
}

function OnTriggerExit(col: Collider)

{

if(col.tag == "Player")
{
   col.transform.parent = null; 
}
}

i don’t really understand your problem though

Ok maybe i did not be clear, i need a platform that moves only if the player is standing on it. btw your script works but the platform does not move.

–

Use a boolean to define when the guy is on:

   var isOn : boolean = false;
   var basPos : Transform;
   var target : Transform;
   var step : float = 0.5f;

   function OnTriggerEnter(col:Collider){
      if(col.tag == "Player")
          isOn = true;
   } 
   function OnTriggerExit(col:Collider){
      if(col.tag == "Player")
          isOn = false;
   }

   function Update(){
       if(isOn)
           transform.position = Vector3.MoveTowards(transform.position, target.position, step);
       else if(tranform.position != basePos.position)
           transform.position = Vector3.MoveTowards(transform.position, basePos.position, step);
   }

This is just a start . You can improve it later but you can strt off with this already.

Yes but you had the parenting already.I thought you were after the moving of the platform.

–

I really thank all of you for the help, the platform now moves when the player steps on it, and i don't even need to parent them!!!

–