3D label as sprite

Started by MEGAMIND, Jan 29, 2025, 03:16 PM

Previous topic - Next topic

MEGAMIND

Well what i am trying to do is set a sprite on players head and rest of the players could see it

spriteppt_label <- {
    "gui_element" : GUISprite("vol.png", VectorScreen(-100, -100)), // Initially hidden, this will hold the GUI sprite element
    "position_3d" : Vector(-1736.89, -250.225, 14.8683), // The initial 3D position of the sprite
}

case 322:
local lplayer = World.FindLocalPlayer();
if (!lplayer) return; 
local lpos = lplayer.Position;
for (local i = 0; i < MAX_PLAYERS; ++i) {
    local player = World.FindPlayer(i); 
    if (player) {
        local spos = player.Position;  // Get this player's position

        // If this player is within 50 units of the local player
        if (Distance(lpos.X, lpos.Y, lpos.Z, spos.X, spos.Y, spos.Z) < 50) {
           
            // Recreate the sprite if it has been deleted
            if (::spriteppt_label.gui_element == null) {
                ::spriteppt_label.gui_element <- GUISprite("vol.png", VectorScreen(0, 0));  // Create sprite
                ::spriteppt_label.Size = VectorScreen(5, 5);  // Adjust sprite size as needed
            }

            // Update 3D position slightly above the player's head
            ::spriteppt_label.position_3d = spos + Vector(0, 0, 1.9);  // Offset by 1.9 units above the player's head

         
            local label_pos = GUI.WorldPosToScreen(::spriteppt_label.position_3d); 
            if (label_pos.Z < 1) {
                ::spriteppt_label.gui_element.Position = VectorScreen(label_pos.X, label_pos.Y);
            } else {
::spriteppt_label.gui_element.Position = VectorScreen(-100, -100);  // Move off-screen
            }
        } else {
            if (::spriteppt_label.gui_element != null) {
                ::spriteppt_label.gui_element <- null;
            }
        }
    }
}

break; case 323:
            ::spriteppt_label <- null;
            break;


This is what i am looking for



idk what wrong with it

@umar4911 @habi2 @vito @Sebastian

habi2

I think the sprite you are creating is 2D. You have to use GUI_FLAG_3D_ENTITY flag and Position3D property. See topic "Major Server Update Released" or 3d laser line by vito

MEGAMIND

Quote from: habi2 on Today at 04:37 AMI think the sprite you are creating is 2D. You have to use GUI_FLAG_3D_ENTITY flag and Position3D property. See topic "Major Server Update Released" or 3d laser line by vito
thanks ill chefk and get back