Hi everyone!
I am having a problems with forcing a part to follow the mouse on a parts axis (The part is rotated). This video here explains it:
How can I achieve this?
Hi everyone!
I am having a problems with forcing a part to follow the mouse on a parts axis (The part is rotated). This video here explains it:
How can I achieve this?
Can you show the code you are using to choose the position?
Its fine this time but next time copy and paste the text, otherwise if I need to copy and paste something to show you a change I can’t.
local GlowingPart = Instance.new("Part")
GlowingPart.Size = Vector3.new(Item.Cube.Size.X + 0.05, Item.Cube.Size.Y + 0.05, 0.05)
GlowingPart.Color = Color3.fromRGB(255, 255, 255)
GlowingPart.Material = Enum.Material.Neon
GlowingPart.CanCollide = false
GlowingPart.Parent = game.Workspace
RunServiceConnection = RunService.RenderStepped:Connect(function()
GlowingPart.CFrame = CFrame.new(Item.Cube.Position.X, Item.Cube.Position.Y, GetMouse.Hit.Z) * CFrame.Angles(0, math.rad(-Item.Cube.Rotation.Y), 0)
end)
Subtract the cube position from the mouse position.
Take that and Dot it with Cube.CFrame * YourAxis (for example Vector3.zAxis), this is the distance along the desired axis with 0 being aligned with the cube center.
Set the glowing part’s CFrame to the Cube’s CFrame + distance * YourAxis
is this right?
RunServiceConnection = RunService.RenderStepped:Connect(function()
local SubtractCubePosFromMousePos = GetMouse.Hit.Position - Item.Cube.Position
local Distance = SubtractCubePosFromMousePos:Dot(Item.Cube.CFrame * Vector3.zAxis)
GlowingPart.CFrame = Item.Cube.CFrame + Distance * Vector3.zAxis
end)
(I might only answer in a few hours again because its really late over here)
Yes but I realized I made a mistake, use this:
RunServiceConnection = RunService.RenderStepped:Connect(function()
local SubtractCubePosFromMousePos = GetMouse.Hit.Position - Item.Cube.Position
local WorldAxis = Item.Cube.CFrame:VectorToWorldSpace(Vector3.zAxis)
local Distance = SubtractCubePosFromMousePos:Dot(WorldAxis)
GlowingPart.CFrame = Item.Cube.CFrame + WorldAxis * Distance
end)
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.