Orggrim
1
Hi, I have a checkpoint object that im trying to move up a bit when the player activates it.
When said player collides with the trigger, i would want the object to slowly move up a certain height(lets say 5)
Any ideas on how to do this? Ive tried a few things but they resulted in it looking like a regular transform.Translate, which is not what i needed.
Any help would be greatly appreciated! Thanks again.
Move any object to any place at any speed (units/seconds) or in any time – all done without using Update:
StartCoroutine (MoveOverSeconds (gameObject, new Vector3 (0.0f, 10f, 0f), 5f));
public IEnumerator MoveOverSpeed (GameObject objectToMove, Vector3 end, float speed){
// speed should be 1 unit per second
while (objectToMove.transform.position != end)
{
objectToMove.transform.position = Vector3.MoveTowards(objectToMove.transform.position, end, speed * Time.deltaTime);
yield return new WaitForEndOfFrame ();
}
}
public IEnumerator MoveOverSeconds (GameObject objectToMove, Vector3 end, float seconds)
{
float elapsedTime = 0;
Vector3 startingPos = objectToMove.transform.position;
while (elapsedTime < seconds)
{
objectToMove.transform.position = Vector3.Lerp(startingPos, end, (elapsedTime / seconds));
elapsedTime += Time.deltaTime;
yield return new WaitForEndOfFrame();
}
objectToMove.transform.position = end;
}
ArkaneX
2
Take a look at Vector3.Lerp example.
If it might sound good, u might use animations also