hi all
I’m trying to make an hp bar using the drawLine()
I figured out how to draw the line but don’t know how to make it follow an object
# import Rasterizer
import Rasterizer
def hpbar(cube):
size = .5
height = .5
a, b, c = cube.position
x = [a-size, b, c+height]
y = [a, b+size, c+height]
green = [0.0,1.0,0.0]
black = [0.0,0.0,0.0]
## draw the LIne
Rasterizer.drawLine(x,y,green)
Rasterizer.drawLine(x,y,black)
I don’t get any errors with this but once i ‘def hpbar(cube):’ it doesn’t draw it
# import Rasterizer
import Rasterizer
cont = GameLogic.getCurrentController()
own = cont.owner
hit = cont.sensors
size = .5
height = 1
a, b, c = own.position
x = [a-size, b, c+height]
y = [a+size, b, c+height]
green = [0.0,1.0,0.0]
black = [0.0,0.0,0.0]
## draw the LIne
Rasterizer.drawLine(x,y,black)
Rasterizer.drawLine(x,y,green)
this actually draws the line, now I just need to find out how to make so its always facing the camera which I think is impossible.
Yeah, draw line is of limited use.
Use a plane with an IPO on the overlay scene.
Or a plane set to ‘halo’ parented to the object you want the HP bar for.
I always think:
HP = hit points
hp = hewlett packard
drawLine() works by taking a start pos and an end pos and drawing a line one pixel thick between them. It looks to me like you are trying to draw a rect.
Try this:
import Rasterizer
def draw_hp_bar(object):
hp = object['hp'] # a property on the object as a percentage of hp
width = 1.0 # 1 blender unit
height = 1.0
x, y, z = object.worldPosition
p1 = [x - width/2, y, z + height]
p2 = [x - width/2 + (width * hp / 100), y, z + height]
Rasterizer.drawLine(p1, p2, [0.0, 1.0, 0.0])
p1 = [x - width/2 + (width * (hp/100)), y, z + height]
p2 = [x + width/2, y, z + height]
Rasterizer.drawLine(p1, p2, [0.0, 0.0, 0.0])
Make sure you call the function every frame as the line will be removed on the next frame update.
If you want a big fat hp bar and you are confident in your python, you can make a switch to the latest version of blender, grab the bgui and create a custom widget using bgl which is blender’s python wrapper for GL. If not, textured planes will do.