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

Rotating Part With Mouse?

Asked by 5 years ago
Edited 5 years ago

This is a video of my current progress So I redid the code using the Raycasting method and it works way better! The only problem is sometimes the beam glitches to random areas. I don't know why it does this, but I think it has something to do with the Ray.

Here's the new method:

First I created a visual part ( I use this part to represent effects that I hope to add latter) that spawns a couple studs in front of the character. After this I create the beam part, that spawns right inside the Visual part.

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)

I have another function create the Visual part and beam Part. This code is meant to update the beam's CFrame

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

The beam gets created and it's direction is adjusted when I move my mouse, but the length and positioning sometimes is incorrect.

Any advice would be appreciated, i've been stuck on this for weeks... lol

If you need help visualizing this should help https://www.youtube.com/watch?v=eqqBj3981SU (Like the beams in Lego Marvel SuperHeroes)

Thanks Again,

0
Could you please show all of your code so we know what each variable is? DeceptiveCaster 3761 — 5y
0
I'm pretty sure you have to raycast... Maginatoc -5 — 5y
0
What Mag said, try making a raycast from the moue position (mouse.hit) and the part and see if that can get anything from there Joshument 110 — 5y
0
Will do awsomemike4 3 — 5y
View all comments (2 more)
0
So, previously I've tried using Raycasting to create this effect, but I ran into a problem. I wanted to only create one part and then rotate that one part. When I tried Raycasting, the only way I knew how was to constantly raycast and then create a new part to match the rays position. Is there anyway to get the Ray's direction and then update the part's direction? (Sorry if Im not explaining well) awsomemike4 3 — 5y
0
I updated this forum, I don't know if you can see me previous post... awsomemike4 3 — 5y

Answer this question