I want to make a drawing game where people can draw on buildings and stuff.
It will be easier to explain for me through images since English isn’t my first language.
What I’m trying to do (match the part that spawns match the angle on the part where the player mouse hovers. Also I want the front face facing up):
This is my script:
local userInputService = game:GetService("UserInputService")
local players = game:GetService("Players")
local runService = game:GetService("RunService")
local localPlayers = players.LocalPlayer
local mouse = localPlayers:GetMouse()
local on = false
userInputService.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.E then
on = true
while on do --// i know i can use renderstepped but im testing something.
local p = Instance.new("Part")
p.Anchored = true
p.CanCollide = false
p.CanQuery = false
p.CanTouch = true
p.Size = Vector3.new(0.5, 0.5, 0.5)
p.CFrame = mouse.Hit
p.Parent = workspace
p.Color = Color3.fromRGB(255, 0, 0)
task.wait(1)
end
end
end)
userInputService.InputEnded:Connect(function(input)
if input.KeyCode == Enum.KeyCode.E then
on = false
end
end)
It might not work, but finding the hypotenuse using the pythagorean theorem (a² + b² = c²) and applying that number to the Y axis of the orientation could work.
It very well might not, though. It’s a bit of a stretch
Another easy is because the WedgeOrientation changes only with the X and Y axis (correct me if I’m wrong) you could check this and do some calculations that (hopefully) are easier the Pythagorean Theorem
only possible with raycasting, using the normal of the ray you can calculate the correct rotation
local ray = workspace:Raycast(workspace.CurrentCamera.CFrame.Position,mouse.Hit.LookVector*1000)
local normal = (ray and ray.Normal) or Vector3.new(0,0,0)
p.CFrame = CFrame.new(mouse.Hit.Position,mouse.Hit.Position+normal)
In all seriousness, using the Pythagorean theorem would be much easier. Could be done very simply with something like this:
local wedge = workspace:WaitForChild("Wedge")
local function getHypotenuse(part: WedgePart) : number
local aSquared = part.Size.Z * part.Size.Z
local bSquared = part.Size.Y * part.Size.Y
local cSquared = aSquared + bSquared
local c = math.sqrt(cSquared)
return c
end
local hypotenuse = getHypotenuse(wedge)
print(hypotenuse)
And you can even vary which one you need if you ever needed both or a specific one. You could just return both c² and c, then create a variable to follow that:
local wedge = workspace:WaitForChild("Wedge")
local function getHypotenuse(part: WedgePart) : number
local aSquared = part.Size.Z * part.Size.Z
local bSquared = part.Size.Y * part.Size.Y
local cSquared = aSquared + bSquared
local c = math.sqrt(cSquared)
return cSquared, c
end
local cSquared, hypotenuse = getHypotenuse(wedge)
print(cSquared, hypotenuse)