- Home /
 
moving platforms
Hi community
Im looking for a simple solution. with a this script i make the platforms in my 2D-game move. the problem is that my character cant stand on the moving platforms. im using the PlatformerController-script for my character. is there a logical solution for this?
 var amplitude: float = 5; // platform excursion (+/- 5 units, in this case)
 var speed: float = 0.2; // movements per second
 var direction: Vector3 = Vector3.forward; // direction relative to the platform
 private var p0: Vector3;
 
 function Start(){
   p0 = transform.position;
   while (true){
     // convert direction to local space
     var dir = transform.TransformDirection(direction);
     // set platform position:
 transform.position = p0 + amplitude * dir * Mathf.Sin(6.28 * speed * Time.time);
     yield; // let Unity free till the next frame
   }
 }
 
              
               Comment
              
 
               
              Hey, you have while true! That doesn't mean while p0 is true. Then you have to do while(p0){}.
Answer by Tijs · Jan 07, 2013 at 06:05 AM
Looks likes this fixed it mostly
 function OnTriggerStay(other:Collider){
 
            if(other.gameObject.tag == "platform"){
            transform.parent = other.transform;
 
        }
     }
 
 function OnTriggerExit(other:Collider){
     if(other.gameObject.tag == "platform"){
          transform.parent = null;
 
        }
     }  
 
               Thanks guys!
Your answer