Change Lerp duration

Hi guys,

I’m trying to implement some kind of entity following mechanism (e.g. a seeker missile or a plane following another one). I thought it would be a quick and easy solution to use a position lerp on the following entity. But since I try to make it work when the followed entity is moving it keeps getting more and more hacky (changing the end position in a task while the entity is moving and other nasty stuff).
Now, my question is can I change the duration of my pos-lerp so that the following entity doesn’t speed up in the process of trying to catch up to the other?
Or do you propose a totally different approach?

Just to clarify, I initially chose a lerp because it appeared to me it was really easy to make the follower lean into a curve etc. while chasing…

Best regards,
Paco1

Is this answered elsewhere? This question comes up early in search results for a similar issue!

I think you might just have to orient the object to face the center point of the target object and just move it forward by it’s facing vector.

1 Like

Gergely’s answer would be my suggestion, too.

You could even then apply some control to the rate at which the object turns.

(Indeed, it’s what I usually do myself, I believe.)

(An alternative is to essentially take the inverse approach: instead of having the object turn towards the target and move forwards, you accelerate the object towards the target and orient it to face along its resultant velocity.)

Unless there’s a particular reason that you want to use a lerp?

Dammit, okay, I’ll just have to sort my model out so that the front of it is the front :sweat_smile::sweat_smile: I think I’m covering for my lack of blender skills a little- the face-towards method would work fine if I hadn’t oriented the arrow to point up :woman_facepalming:

1 Like

If your model is loaded from a file, then it’s likely that the actual model is in in fact in a child-node of the node that you get when you load it.

As such, you can potentially just access this child-node and adjust it to account for the direction of your arrow, thus allowing you to use the main node without further alteration!

(i.e. Something like this: myLoadedModelNP.getChild(0).setP(-90)

(Or, if you find that your node doesn’t have such a child-node, just add a new parent-node above it (and below whatever you were attaching it to previously), allowing you to adjust your node as called for and treat the new parent-node as your “main” node.

For a simple example:

### Instead of this:
myNode.reparentTo(myShowBase.render)

### You might have this:
myNode.setP(-90)

newParent = NodePath(PandaNode("my parent node"))
newParent.reparentTo(myShowBase.render)
# Or, more simply:
# newParent = myShowBase.render.attachNewNode(PandaNode("my parent node"))

myNode.reparentTo(newParent)