Moving an actor along hpr with interpolation

I’m new to panda, and I’m having a hard time finding out how to move an actor forward using interpolation.

Presently, here’s how I’m moving the actor:
self.pandaActor.setPos(self.pandaActor, 0, distanceMoved, 0)

This works fine, but is of course very choppy. I’d like to be able to calculate how far the actor will move between this update and the next update, then set up an interval to move the panda over the amount of time from now until the next update for the distance. The problem is that I don’t know how to tell it the destination. setPos calculates the distance using the hpr of the pathnode, but posInterval doesn’t seem to calculate that for you. How do I get this point from panda?

The previous post was from me.

Hmm, I’m a little confused. By update, do you mean each frame? I’m not quite sure what value there is in applying an interval that only runs for one frame, since you won’t see the object in any of the points in between–you might as well just use setPos() each frame.

If, on the other hand, you want to just fire off a posInterval that moves the object smoothly over a definite period of time, then you don’t need to worry about elapsed time between updates, since the posInterval automatically calculates that correctly.

But if you’re using setPos() every frame (which is fine), you can get the elapsed time since the last frame via globalClock.getDt(); then you can calculate the distance moved via something like:


distanceMoved = speed * globalClock.getDt()

David

Thanks. What I meant by update is an update of position information for the actor. New position information isn’t going to be available for the actor each frame, so I am going to use prediction smooth animation.

Ah, I see. Sorry for the misunderstanding. So you need to figure out what (x, y, z) point is distanceUnits forward from the actor.

One cheesy way to do this (I’ve done this before, I have no shame) is to take advantage of the setPos calculation:

orig = actor.getPos()
actor.setPos(actor, 0, distanceUnits, 0)
newPos = actor.getPos()
actor.posInterval(lerpTime, newPos, startPos = orig)

There are other ways to calculate this value without having to reset the node’s position forward and back again, but this way is pretty easy to understand and works in all sorts of situations.

David

Thanks! That will work beautifully. I’m writing a two-player network pong game so that I can beef up on panda3d. I’m having a hard time finding some information, as the manual doesn’t go that in-depth. I think I’ll write a tutorial to go along with the source.

Thanks again!