Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Rotating part via mouse?

Asked by 4 years ago

Hey everyone, so I posted this problem a couple weeks back, but I never really got an answer. Anyway, I want to create a beam that can move via the mouse movement, but i've been running into many problems.

Here's the current script:

(Local Script)

  Mouse.Button1Down:Connect(function()  
            mousedown = true
            CVB:FireServer() -- Creates the Visual Part and Beam        
            Mouse.move:Connect(function()
            if not mousedown and not player and not Humanoid and not Humanoid.Health > 0 and not Torso and not debounce then return end     
                local MouseHit = Mouse.Hit
                local HumanoidRoot = Character:WaitForChild("HumanoidRootPart")
                local Distance = (Torso.Position-MouseHit.Position).magnitude
                if Distance > 500 then  Distance = DistanceMax end 
                FlameStart:FireServer(mousedown,Torso,MouseHit,Distance)    -- Creates the RayCast and updates the beam's CFrame
            end)
        end)

After firing the remote event the server script picks it up and does all of the beam's CFrame repositioning. On the server side a function creates a Visual part and beam Part. (P.S. I did not include the full function that creates the parts, if you need me to do so just comment please)

   FlameStart.OnServerEvent:connect(function(...)
        local tuple = {...}



                local player = tuple[1]
                local mousehit = tuple[2]
                local Torso = tuple[3]
                local MouseHit = tuple[4]
                local Distance = tuple[5]

                if Torso and MouseHit and player.Character and Distance then

                    --Ray Cast--
                    local ray = Ray.new(Torso.CFrame.Position, (MouseHit.Position - Torso.CFrame.Position).Unit * 500)  
                    local part,position = workspace:FindPartOnRay(ray,player.Character,false,true)

                    --UpdateBeam's CFrame -- 
                    beam.Size = Vector3.new(0.5,0.5,Distance)
                    beam.CFrame = CFrame.new(Torso.CFrame.Position ,position) * CFrame.new(0,0,-Distance/2)
                end 
            end     
        end

This script has worked, but the only problem is that sometimes the beam glitches out and is positioned wrong.

This is a video of my current progress](https://photos.app.goo.gl/46YabKKzf2FX9FDR8)

All help would be appreciated, thanks alot

btw if you need help visualizing Im trying to make the beam like in lego marvel superheros.

Here's the link https://www.youtube.com/watch?v=eqqBj3981SU

1 answer

Log in to vote
0
Answered by 4 years ago

The problem that I was having with the script was because of the raycast. The ray did not ignore the beam, and as a result many errors were returned by the raycast.

To fix the problem, instead of using workspace:FindPartOnRay(), I used workspace:FindPartOnRayWithIgnoreList(). I created a table with objects that I wanted the raycast to ignore(mainly being the player, and the Beampart itself), and then included that within the parameter of the function.

I found that this method works best, it allows the function to work the best, with no errors! :D

Thanks for the help and suggestions on my previous post :D Thank God I got a solution - i've been stuck for months!

Ad

Answer this question