Brief: We click on an object's front surface, and it applies a ImageLabel centered around the mouse. The size is constant on all different sizes.
Problem 2: I can't apply this to all surfaces, I've already got the Surface's Normal being returned, but from there on, I don't know how to apply this information.
Here is me code:
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local Texture = "http://www.roblox.com/asset/?id=82021756"
local Sizer = 20
function Positioning(part,hitpos)
local PixelRef = part.CFrame:toObjectSpace(CFrame.new(hitpos))--*CFrame.new(-part.Size.X/2,-part.Size.Y/2,0)
local XRef = -PixelRef.p.X-- -math.ceil(PixelRef.X) If we want this to be applied on a stud=pixel scale (Messes up positions)
local YRef = -PixelRef.p.Y-- -math.ceil(PixelRef.Y)
return XRef,YRef
end
function click()
local target = mouse.Target
if target then
local mRay = mouse.UnitRay
local ray = Ray.new( mRay.Origin, mRay.Direction * 100 )
local part, pos, normal = game.Workspace:FindPartOnRay( ray, player.Character )
if part then
print(part.Name,pos,normal)
local surface
local frame
if part:findFirstChild("SurfaceGui") then
surface = part:findFirstChild("SurfaceGui")
frame = surface.Framey
else
print("Found none")
surface = Instance.new( "SurfaceGui", part)
surface.CanvasSize = Vector2.new(part.Size.X*10,part.Size.Y*10)
frame = Instance.new("Frame", surface)
frame.Name = "Framey"
frame.Size = UDim2.new(1,0,1,0)
frame.ClipsDescendants = true
frame.BackgroundTransparency =1
end
local Tex = Instance.new("ImageLabel",frame)
Tex.Image = Texture
Tex.Size = UDim2.new(0,Sizer,0,Sizer)
Tex.BackgroundTransparency = 1
local X,Y = Positioning(part,pos)
print(X,Y)
Tex.Position = UDim2.new(.5+(X/(part.Size.X)),-Sizer/2,.5+(Y/(part.Size.Y)),-Sizer/2)
end
end
end
mouse.Button1Down:connect(click)
I've figured out where I was going wrong with the application, but I don't understand how I need to edit this to apply to other surfaces.
