Making Objects Move on Trigger

Hi! I´m super new to scripting and that stuff but I´m trying to get better at it by searching for tutorials and that so I can learn how to make stuff work! :stuck_out_tongue:

What I want help with, and I have tried to make it my selfe first without succes, is to make an object move up and down wen triggered! I know how to fix the trigger, the problem is how to fix the object move up and down like an elevator!

I don´t want it to be controll based, I want it to be aoutomatic and always move up and down wen triggered… I´ve tryed using > < ( wen its < 0 it goes up and wen its > 10 it goes down for example) in different if statements but failed and wen I´ve searched for it I´ve got the wrong kind of results… If a noob could get some help?

Oh, btw. I´ve read wile searching the forums for help that the player clip through the moving objects! If so how can I fix that problem?

I know I´m basicly asking for a finished script but I need to learn some how and if I can´t find my awnser I gues this is how it has to be done… :s

Show us what you have done so we can “help” you, after all, as you stated, “i need to learn some how”, and this is the perfect way.

Well, now I´ve deleted that script :s But it was something like this:

function Update(){
if(GameObject.Location > (0,5,0)){
transform.position(0.-1.0);
}
if(GameObject.Location < (0,1,0)){
transform.position(0,1,0);
}
}

And I know this don´t work :stuck_out_tongue:
And after searching some more on the web I found this:

function Update () {
var translation : float = Time.deltaTime * 1;
transform.Translate (0, translation, 0);
}

Just that it keeps on going and I don´t know how to make it stop and go back down… :stuck_out_tongue:

you can use Vector3.Lerp which makes things go from one point to another point.

Ok, I could look that up! Tnx! :slight_smile:

(More help is still welcome XP)

Ok, so i found this and it works! I can stand on it and all that… Now I just want/need to know how to make it go back to the original position and back up again and so on! :stuck_out_tongue:
Some sort of if statement? Add another variable? I tried some but no real progress… :frowning:

var target : Transform;
var smooth = 0.5;
function Update () {
transform.position = Vector3.Lerp (transform.position, target.position, Time.deltaTime * smooth);
}

I tried something like this:

var target : Transform;
var target2 : Transform;
var smooth = 0.5;
function OnTriggerEnter(other : Collider){
if(other.tag == “Start”){
transform.position = Vector3.Lerp (transform.position, target.position, Time.deltaTime * smooth);
}

if(other.tag == “Stop”){
transform.position = Vector3.Lerp (transform.position, target2.position, Time.deltaTime * smooth);
}
}

I fixed my problem! Got some help by a friend…

Here is the code:

var target : Transform;
var target2 : Transform;
var smooth = 0.5;
var lol = false;

function OnTriggerEnter(other : Collider){
if(other.tag == “Player”){
lol=true;
}
}

function OnTriggerExit(other : Collider){
if(other.tag == “Player”){
lol= false;
}
}

function Update()
{
if(lol == true)
transform.position = Vector3.Lerp (transform.position, target.position, Time.deltaTime * smooth);
else
transform.position = Vector3.Lerp (transform.position, target2.position, Time.deltaTime * smooth);

}

All that needs to be done is add in the trigger than its good to go! And that I know how to do! XD (Add another if statement under the if(lol == true))

Thank you Ellis i was Thinking about how to do this myself and didn´t really get it but this is perfect