How to use LineSegs ?

I have this class documentation but still don’t understand very well how it works. Could someone show me an example of how to implement a tractor beam (a line from one object to another that changes with their position) ?

Thanks in advance.

Hey zingbat,

have a look at my steering behaviors example:

you can ignore most of it, but one of the modules it includes is ‘’: ‘a library of primitive drawing functions (lines, circles, rectangles, grid, reticles etc) built on top of Panda’s LineSegs class’. ‘’ uses LineSegs also, and moves a LineSeg around with a vehicle like you were asking for.

Also take a look at this thread:

Also, the Rope class, using an order of 2, can be used to draw a connected line segment between two nodes.


Here is some example code showing how to draw a 3D axes set. For your application you would need to create a similar object for the tractor beam. For each frame you would pass your function the coordinates of the two objects and have it create a NodePath for the line, remove your old tractor beam (the NodePath from the previous frame), and reparent this new Nodepath to render.

# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

def P3DCreateAxes(lineThickness=1):

	ls = LineSegs()

	# X axis
	ls.setColor(1.0, 0.0, 0.0, 1.0)
	ls.moveTo(0.0, 0.0, 0.0)
	ls.drawTo(1.0, 0.0, 0.0)

	# Y axis
	ls.setColor(0.0, 1.0, 0.0, 1.0)
	ls.drawTo(0.0, 1.0, 0.0)

	# Z axis
	ls.setColor(0.0, 0.0, 1.0, 1.0)
	ls.drawTo(0.0, 0.0, 1.0)

	node = ls.create()
	return NodePath(node)
1 Like

Can we use nodes created with LineSegs for collision detection? The behavior i’m trying to create is that if something like a meteor or a missile collides with the tractor beam it will disrupt it.

maybe a collosion segment might be what you’r looking for- check the manual about it.

I have it working now. Thanks all.