Jump to content

Clicking on 3D Rectangle


iNev.

Recommended Posts

Posted

Hey, can someone make me a simple script that checks if player clicks on a 3D Rectangle?

local x,y,z = 0, 0, 3
local sx,sy = getScreenFromWorldPosition(x,y,z)

if sx and sy then
      dxDrawRectangle(sx - 75, sy - 18.75, 200, 37.5, tocolor(0,0,0,200), false)
      dxDrawText("text", sx - 37.5, sy - 8, sx - 37.5, sy - 8, tocolor(255,255,255,255), client.scale, "clear")
end

 

'local x,y,z' is just an example, these variables is changing every second so I don't really know how to do it.

Posted

Use event onClientClick, and check whether absoluteX, absoluteY are in DX rectangle's region.

if ( absoluteX >= positionX and absoluteX <= positionX + width ) and ( absoluteY >= positionY and absoluteY <= positionY + height ) then
  -- clicked on the rectangle.
  -- don't forget to check whether its a LMB click or RMB, and whether it was pressed or released.
end

 

Posted
1 hour ago, MrTasty said:

Use event onClientClick, and check whether absoluteX, absoluteY are in DX rectangle's region.


if ( absoluteX >= positionX and absoluteX <= positionX + width ) and ( absoluteY >= positionY and absoluteY <= positionY + height ) then
  -- clicked on the rectangle.
  -- don't forget to check whether its a LMB click or RMB, and whether it was pressed or released.
end

 

Yeah I know, but you check this on a 2D rectangle. My rectangle is on a place in the world, not the screen.

Posted

You can do the same calculations in the onClientClick event as you used in render, to find where the positionX and positionY are.

--onClientClick
local positionX,positionY = getScreenFromWorldPosition(x,y,z)

 

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...