- Home /
Transform localPosition on time
Hey outthere
We found a lot of script who rotate a door or something by pressing a key during a time. Our problem is now to write a script who lift up our car in a few seconds (smooth animation). ex. Press "K" and the car lift up 50cm over the ground in 2-3 seconds (during this time it goes upwards.
At the moment the script lift the car 5cm on each Key-Press.
Best Regards from Switzerland MischiMusch12
P.S. The script at the moment:
function Update () {
var translation : float = Time.deltaTime * 45;
var duration : float = 1.0;
if (transform.localPosition.y > 0.16)
{
if (Input.GetKeyDown ("f"))
{
transform.localPosition = Vector3(transform.localPosition.x * 1,transform.localPosition.y - 0.2, transform.localPosition.z * 1);
}
}
if (transform.localPosition.y < 1.15)
{
if (Input.GetKeyDown ("g"))
{
transform.localPosition = Vector3(transform.localPosition.x * 1,transform.localPosition.y + 0.2, transform.localPosition.z * 1);
}
}
}
Answer by Jessespike · Sep 28, 2012 at 04:15 PM
Changed GetKeyDown() to GetKey()
Changed transform.y +/- 0.2 to transform.y +/- translation
function Update () { var translation : float = Time.deltaTime * 45; var duration : float = 1.0; if (transform.localPosition.y > 0.16) { if (Input.GetKey ("f")) { transform.localPosition = Vector3(transform.localPosition.x * 1,transform.localPosition.y - translation, transform.localPosition.z * 1); } } if (transform.localPosition.y < 1.15) { if (Input.GetKey ("g")) { transform.localPosition = Vector3(transform.localPosition.x * 1,transform.localPosition.y + translation, transform.localPosition.z * 1); } } }
Answer by MischiMusch12 · Oct 01, 2012 at 01:21 PM
Hey Jessespike
Thank you for your answer, but it's not exactly what we are looking for. We would like to Press the Key once and then the car lift up. A short press of the button....not still pressing until the car is full lifted.
Die Taste soll kurz gedrückt werden, damit die Hydraulik sich ausfährt...nicht das wir mehrere male drücken müssen oder die Taste gedrückt halten müssen.