health above enemy head?

Blitz3D Forums/Blitz3D Beginners Area/health above enemy head?

Guy Fawkes(Posted 2009) [#1]
Hi all. This code works SORTA, the problem is if the enemy is too big, it wont ALWAYS display the health above the enemy's head. i need it to ALWAYS stay above the enemy's head no matter HOW big the enemy is. and if the enemy moves, the y position of the label stays the same no matter what height the enemy is at.

code:



Thanks for the help as usual! :)


GfK(Posted 2009) [#2]
Position a pivot above his head in 3D space where you want the label to be, parent it to the player entity, and use that as a point of reference instead of the player entity itself.


Ross C(Posted 2009) [#3]
You could also try 2d and camera projest i suppose. That would keep the graphic the same size. Mixing 2d and 3d can give slowdowns though...


Guy Fawkes(Posted 2009) [#4]
i like the entity parent thing better. i tried it, im not having problems w/ the entityparent pivot above the players head, im having trouble where the labelentity text is located.


Kryzon(Posted 2009) [#5]
What you mean? Why don't you just center the text?

Since you are getting the projection for the center of the "name pivot", only makes sense to center your text (by using Text txt$,x,y,TRUE,TRUE).


Guy Fawkes(Posted 2009) [#6]
right, b/c if the enemy say jumps up and down, the text of the enemy doesnt stay above his head and jump with it. it stays in the middle of the enemy's body if close up, and only stays at the top of his head when far away. but i will try this. ill let u know the results


Kryzon(Posted 2009) [#7]
If it stays in the middle of the enemy's body when close up that means that the pivot is wrongly placed.

Don't you have a "Head Bone" or something that you can project the coordinates into screen?
I'm guessing you are using skeletal animation here. If your enemies are simpler (simple primitives or shapes that don't need bones), then you really need to go testing out what works and what doesn't.

Don't mind the far away distance. Focus on testing the text's position when it's close up to the camera (it's when the position will be more accurate).


Guy Fawkes(Posted 2009) [#8]
o i fixed the pivot. i just have to fix the position of the text now


_PJ_(Posted 2009) [#9]
To do that, make sure the text label is 'projected' onto the Pivot, not the entity.

LabelEntitys(camera, label$, PIVOTHANDLE)



Guy Fawkes(Posted 2009) [#10]
working on it as we speak ^^


Guy Fawkes(Posted 2009) [#11]
not working..

also, its only positioning the pivot above small enemy's heads. not large scale enemies.

so far, i have this above updateworld in the main loop:



this here is the labelentitys function:



i have this inside createhostile() :



the viewable pivot (a sphere for now so i can see it), is under the line where i defined "A\model = "..

i call createhostile() like this:



i call the gosub reset like this in the main loop:



and finally, i call RESETR from inside updateplayer() like this:



and last but not least, i call updateplayer() inside of the main loop

i hope this is enough information to figure out what is going on here ^^


_PJ_(Posted 2009) [#12]
Two things:

1) Is your UpdateWorld after the Renderworld?
Ideally you should have the updateworld before the renderworld, then the LabelEntity call, then the Flip after that.

2)
For b2.hostile = Each hostile
LabelEntitys(Camera, "Enemy: "+b2\model+"|"+b2\hp+"/"+b2\maxhp, healthpoint)
Next

You are applying this label only to a single entity multiple times.

Select spec
			Case 1
				A\model = CopyEntity(enemymesh(Rnd(0,2)))
				healthpoint = CreateSphere(4)
				EntityParent healthpoint, A\model
				PositionEntity healthpoint, EntityX(A\model), MeshHeight(A\model)+2, EntityZ(A\model)

Here, healthpoint is an entity on its own which you overwrite with new copies and assign new parents with every a\model you create (at spec = 1).


I would suggest, that you include the healthpoint into the Type.
For example:

Type hostile
Field blah
field blahblah
field blahblahblah
field healthpoint
End Type


Then amend the labelentitys code to:

For b2.hostile = Each hostile
LabelEntitys(Camera, "Enemy: "+b2\model+"|"+b2\hp+"/"+b2\maxhp,b2\ healthpoint)
Next


Finally, if the b2\model b2\hp and b2\maxhp are declared as integers, then it might be best to ensure they are displayed correctly as:

For b2.hostile = Each hostile
LabelEntitys(Camera, "Enemy: "+Str(b2\model%)+"|"+Str(b2\hp%)+"/"+Str(b2\maxhp%),\healthpoint)
Next


That should help with the immediate issue :)


Guy Fawkes(Posted 2009) [#13]
that didnt work. the problem lays within the labelentitys() function. its not positioning the text onto the healthpoint correctly..

here:

labelentitys():



here's how it's called:



its positioning the healthpoint correctly. not the text.


_PJ_(Posted 2009) [#14]
Where's your Renderworld?

There's little point in applying the function efore the scene's updated as the camera projection won't work correctly.


Guy Fawkes(Posted 2009) [#15]
renderworld tween# ? i tween it cuz on some pcs its 1400+ fps