How can I make an object move up on collision?

How do I move an object downward using the Vector() command? I want to implement a door opening by it sinking into the ground, when the player collides with a button on the ground. I have experimented with this, but nothing seems to work. I tried animation, but the animation has to be done for each door, and sometimes does not work at all. How would I write a simple Vector() script that would move a GameObject up a certain number of Unity units, with the amount set as a variable?


I don’t just want code, I want to know how to do this…

this is very urgent, I need this done by sunday

You want lerp or slerp

they use math to interpolate from one position to the next

interpolate basically means to go from one position to another position by means of
moving really small amounts.

if you’d like i can give you more info about interpolating. Post a request.

Mark as asnwerd

//script attached to door

void update()
 public bool LowerDoor = false;
float FinalHeight = 0f;

vector3 FinalPosition = new vector3 (transform.position.x, FinalHeight, Time.deltatime);

door.trasform.position = vector3.lerp(door.transform.position, FinalPosition);


change the public lowerdoor bool in the collision script.