(Solved)Problem moving object from on position to another in a certain amount of time using lerp()

B

BagarraoEduardo

Guest
Hi all,

I'm migrating a game that I've been developing in Unity to GMS2, and I'm struggling with this part as I don't know how to implement this in GML.

Basically I just wan't to make a object move in one position to another in a certain amount of time throwing balls, just like this.

The code that I used to make this in Unity:

private IEnumerator MoveCoroutine(float desiredPosition, float timeToReachTarget)
{

Vector2 currentPos = transform.position;
Vector2 targetPos = new Vector2(desiredPosition, transform.position.y);
float timePassed = 0f;
while (timePassed < 1)
{

timePassed += Time.deltaTime / timeToReachTarget;
transform.position = Vector3.Lerp(currentPos, targetPos, timePassed);

yield return null;
}
}

I'm trying to do something similar in GMS2 but without result, as the object goes away and the x of the object turns NaN. Here's the code:

Create event

Step event


Please help my, I can't see a way to fix this. Thanks in advance!

Best Regards,
Eduardo Bagarrão
 

2Dcube

Member
delta_time in GMS is in microseconds (1,000,000th of a second). (whereas in Unity it is in seconds).
This should help:
Code:
time_passed += delta_time / 1000000 / time_between_balls;
It was probably getting so big that it started returning NotANumber.
 
B

BagarraoEduardo

Guest
delta_time in GMS is in microseconds (1,000,000th of a second). (whereas in Unity it is in seconds).
This should help:
Code:
time_passed += delta_time / 1000000 / time_between_balls;
It was probably getting so big that it started returning NotANumber.
Thank you! This saved my day! :) Is there some way to mark this thread as Solved?(I'm new on GM Community)
 
Top