- Home /
Duplicate Question
how to move a platform up and down
i wrote a code to move a platform up and down but no object seems to stay on it i.e objects go through it? pls help...because it seems that the script is disabling the platform...
private var Xpos : float; private var Ypos : float; private var max : boolean;
var Vert : boolean; var maxAmount : int; var step : float;
function Start () { Xpos = transform.position.x; Ypos = transform.position.y; //collider.enabled = false; }
function Update () {
if(Vert) { if(transform.position.y >= Ypos + maxAmount){ max = true;} else if(transform.position.y <= Ypos) { max = false;}
} else{ if(transform.position.x >= Xpos + maxAmount){ max = true;} else if(transform.position.x <= Xpos) { max = false;}
}
if(Vert){
if(!max) {
transform.position.y += step;}
else{
transform.position.y -= step;}
}
else{
if(!max){
transform.position.x += step;}
else{
transform.position.x -= step;}
}
}
This question has been asked and answered many times before. Please search before posting a question to make sure you are not posting a duplicate question.
http://answers.unity3d.com/questions/topics/move-with-moving-platform.html
Setting the transform.position is like teleporting the object, it will instantly have the new position and will not affect anything. Read through the other answers to see alternate ways of doing it.