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

How Could I Change a Part's Velocity to Match a User's Mouse Location?

Asked by 4 years ago

This may be more difficult than it sounds. Let's assume a user creates a part through a global script. Is there a way to make that part move in the direction of that user's mouse.Hit.p until the part no longer exists? I have been trying many things, but here is my latest attempt. If anyone knows how to do this, I would be extremely grateful! Thanks in advance.

In a local script within the part that was created...

player = game.Players.LocalPlayer
while wait(.01) do
    if script.Parent ~= nil then
        local mouse = player:GetMouse()
        local position = mouse.Hit.p
        script.Parent.Velocity = CFrame.new(script.Parent.Position, position) * 70
    end
end
0
I dont think you can use a CFrame for Part.Velocity. According to the Wiki at least, it takes a Vector3. In that case, I would just do Part.Velocity = Mouse.Hit.Position. Psudar 882 — 4y
0
I initially had .LookVector appended to the end on line 6 after the parentheses. That didn't work either. corncob567 275 — 4y

1 answer

Log in to vote
1
Answered by 4 years ago
Edited 4 years ago

you need to use a body mover or this will never work, you cant change velocity directly, velocity is just the effect. to change velocity you need to use a bodyvelocity and from this you can do ~~~~~~~~~~~~~~~~~ bodyvelocitypath.MaxForce = Vector3.new(math.huge,math,huge,math.huge) bodyvelocitypath.Velocity = Vector3.new(mouse.Hit.p) ~~~~~~~~~~~~~~~~~

1
Just to note you can change velocity directly. It will only apply the velocity for a small time and gravity will stop it, unless being applied constantly in a loop or runservice connection Wafflecow321 457 — 4y
0
no velocity is just the effect and cannot be changed directly Gameplayer365247v2 1055 — 4y
0
This didn't work... corncob567 275 — 4y
Ad

Answer this question