Posted: 20th Jun 2023 16:33
Hello everyone, I would like to indicate the vitality of an npc in my game with a progress bar above the head, similar to this example:
screenshot : https://prnt.sc/ZIQaAeevijOV
Posted: 20th Jun 2023 18:25
GetScreenX/YFrom3D() would be a start:

+ Code Snippet
// Project: 3D Bars 
// Created: 2023-06-20

// show all errors
SetErrorMode(2)

// set window properties
SetWindowTitle( "3D Bars" )
SetWindowSize( 640,360, 0 )
SetWindowAllowResize( 1 )

// set display properties
SetVirtualResolution( 640,360 )
SetOrientationAllowed( 1, 1, 1, 1 ) // portrait, portrait2, landscape, landscape2
SetSyncRate( 30, 0 )
SetScissor( 0,0,0,0 )
UseNewDefaultFonts( 1 )

CenterWindow()

Type NPC
	ID, VitID
EndType

GLOBAL NPCs as NPC []
MakeNPCs()

SetCameraPosition(1,0,20,0)
SetCameraRange(1,0.1,500.0)
SetCameraRotation(1,0,0,0)

do
	RotateCameraLocalY(1,1)
	SetBars()

    Sync()
loop

Function SetBars()
	For x = 0 to NPCs.Length
		ThisOb = NPCs[x].ID
		ThisV = NPCs[x].VitID
		If GetObjectInScreen(ThisOb)
			x# = GetObjectX(ThisOb)	:	y# = GetObjectY(ThisOb)+15	:	z# = GetObjectZ(ThisOb)
			ThisX = GetScreenXFrom3D(x#,y#,z#)
			ThisY = GetScreenYFrom3D(x#,y#,z#)
			SetSpritePositionByOffset(ThisV, ThisX,ThisY)
			If GetSpriteVisible(ThisV) = 0 then SetSpriteVisible(ThisV,1)
		Else
			SetSpriteVisible(ThisV,0)
		EndIf
	Next x
EndFunction

Function MakeNPCs()
	ThisNPC as NPC
	For x = 1 to 20
		Angle# = x*18.0
		Dist# = Random(50,250)
		R = Random(128,255)
		G = Random(128,255)
		B = Random(128,255)
		ThisNPC.ID = CreateObjectCapsule(10,20,1)
		SetObjectColor(ThisNPC.ID,R,G,B,255)
			SetObjectPosition(ThisNPC.ID, SIN(Angle#)*Dist#, Random(0,30), COS(Angle#)*Dist#)
		ThisNPC.VitID = CreateSprite(0)
			SetSpriteColor(ThisNPC.VitID, R,G,B,255)
			SetSpriteSize(ThisNPC.VitID, 80,10)
		NPCs.Insert(ThisNPC)
	Next x
EndFunction

Function CenterWindow()
	X = GetMaxDeviceWidth()/2.0 - GetWindowWidth()/2.0
	Y = GetMaxDeviceHeight()/2.0 - GetWindowHeight()/2.0
	SetWindowPosition( X,Y)
EndFunction
Posted: 21st Jun 2023 5:36
This is amazing . thanks by you help . I will test it right now.