Jump to content

dxDrawRectangle 3D size


Recommended Posts

Hello everyone !

I'm trying to create a 3D rectangle using dxDrawRectangle + getScreenFromWorldPosition to function as a health bar. I'm having difficulty adjusting the width and height. I want the rectangle to get smaller as it moves away from the ped, until it is no longer rendered.

    local x, y, z = getElementPosition(ped)
    local lpx, lpy, lpz  = getElementPosition(localPlayer)
    local dist = getDistanceBetweenPoints3D(x, y, z, lpx, lpy, lpz)
    if dist > 20 then return end
    local x2, y2 = getScreenFromWorldPosition(x, y, z)
    local health = getElementHealth(ped)
    local per = (health * 70) / 100
    dxDrawRectangle(x2, y2, 70, 9, tocolor(128, 0, 0, 255))
    dxDrawRectangle(x2, y2, per, 9, tocolor(255, 0, 0, 255))

Could someone help me find the correct calculation?

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...