Interval problem

As shown in the following code, I want to implement the interval between each time the character achieves a random change of position. But there is no way to achieve it using various methods. Although the random setting of the character position is now implemented, during the execution interval, the character still returns to the original position before moving. I saw that the document has stated that the engine does not affect the position of the moving node, but it moves after changing the position of the character. Why?

from  panda3d.core import *
import direct.directbase.DirectStart
import random
from direct.interval.IntervalGlobal import *
from import Actor
window = WindowProperties()
envir = loader.loadModel('environment')
ss = Actor('panda')
ff = ss.posInterval(2, pos=(ss.getX(), ss.getY(), ss.getZ()-10))
def change():
    global ff
    ll = (random.randint(-10, 10), random.randint(-10, 10), 0)
kk = Func(change)

In short, I think that the problem is that the values that you’re passing into “ss.posInterval” are evaluated when you run the command that creates the interval, which is just once, before “change” is ever called.

For what you want, you might perhaps construct the interval when “change” is called (i.e. as part of the “change” function).

Although note that this will likely affect how you handle that Sequence-loop: the “ff” stored in there will be the original one, not the new one. Perhaps using a task instead of a looping Sequence might work?

(There might be a way to alter the values in an interval; however, if there is, I don’t know what it might be.)

(Also, I’m not sure of the parameters passed into “posInterval” there, as I don’t seem to be finding a reference to such a method in the Actor class, or its parent-classes… o_0)

OK, all right. I’ll test it again!

1 Like

Although the Panda3D has an example in the manual moving the character using an interval. However, intervals are not suitable for moving. It’s easier to use tasks.