Plotting Trajectory

So I am planning to add something of a trajectory for an object, I will have the points of the object at each frame, but when I got to add lines seg to each frame, all I get are dots at the given point but no line connecting each point. Mind you I am just a beginner and hence I might be doing something really stupid and sorry for it.

My code is as follows in the taskMgr function

 def drawPath(self, task):
        self.line.drawTo(self.X, self.Y, self.Z)
        self.path= NodePath(self.line.create())
        return Task.cont

Thanks for helping, and sorry again if its a very noob question or if I have forgotten to do something fairly simple.

Do I gather correctly that you’re using the “LineSegs” class here?

If so, when you specify the points of the trajectory, are you doing so via calls to “moveTo”, or “drawTo”? My understanding is that the former (at least after its first call for a given line) will result in points, while the latter (presumably with an initial call to “moveTo” in order to set the starting position) will result in lines.

For the first point moveTo, and then to draw each line at each frame it is drawTo. Should I use drawTo everywhere

Hmm… I’m not sure that I’ve used LineSegs myself–and if I do I don’t recall how it’s done–so I’m inferring from the documentation. And from that, and from your description, I gather that you seem to be using it correctly: calling “moveTo” once, and then “drawTo” thereafter.

In which case, perhaps it would be worth seeing the code in which you do this–perhaps that will reveal the source of the issue.

Maybe this may help or do u require the entire code.

# Inside the _init_ function
self.i = 0
self.orbit = LineSegs()
self.orbit.moveTo(self.X[0], self.Y[0], self.Z[0])
    def drawOrbit(self, task):
        self.orbit.drawTo(self.X[self.i], self.Y[self.i], self.Z[self.i])
        self.orbit_path = NodePath(self.orbit.create())
        self.i +=1
        return Task.cont

Hmm, I see–I think that I better understand what you’re doing, at least.

That said, what you have there looks right, at least to my eye. It may be that someone more familiar with the LineSegs class is called for here!

So, for now I think that I’ll bow out in favour of someone else responding, with my apologies.

Hi, welcome to the forums. I think you might want to look at the LineNodePath for connecting two points to each other, here is an example:

gameLine= LineNodePath(render, colorVec = Vec4(0.43, 0.54, 0.99, 1))

If you want to update the line at run time, you could do so using a task, with this code:


You could even use multiple points to draw whatever wire-frame shape you want, I hope it helps. You can read more on how to use it here . Play around with it, if this answers your general question, but you later have specifics, feel free to ask.

Thanks, will try it out and let you know how it goes