Stopping a LerpFunc interval

Hi guys, I am writing a server-client program, right now I am trying to finish the monsters moving part. I recently managed to make the monsters stays on ground on uneven terrain with a collision ray, now I have added some spheres on them so that they won’t enter rocks, wall, etc.
The problem is the following: when a monster start moving I create a LerpFunc interval, that will interpolate the coordinates x and y. So, for every interpolated value:

  1. I save current position
  2. I move the model to the new position
  3. I check if the new position won’t cause the monster to fall
  4. I check if the new position won’t cause the monster to enter a wall

If condition 3 or 4 is true, I restore the monster old position and I wanted to stop the interval right here. I am trying to use the finish() method but is not working (gives a huge error message, it seems it is still trying to call the function).

Any tips?

Hmm, have you considered using a task rather than an interval? It sounds like the function you are trying to perform is more closely suited to the task system.


Thanks for the reply.

Actually I didn’t consider using tasks because Lerp intervals automatically interpolates the values for me. Not that it would be hard to do so myself, but since the function from panda was implemented in C it is faster than the one I would write (in python).
Also, isn’t using tasks heavier than Lerp invertals?


Tasks aren’t heavier than lerps in general (though it’s possible to write a too-heavy task, of course, just as it’s possible to write a too-heavy lerp).

The lerp equation is (a + t * (b - a)). It’s true that this equation is computed in C with a LerpFunctionInterval, and that’s faster than the same computation in Python, but since it’s such a simple equation it’s not going to make a very big difference. The rest of the overhead of the lerp or the task is going to dwarf that calculation.

The biggest limitation with intervals is that they are not designed to be dynamic: an interval, once created, is designed to play for a set amount of time and then stop. You can interrupt it with a call to finish() or pause(), but you can’t call this within the lerp function itself.