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

How would I set a set speed for the velocity of a brick?

Asked by 5 years ago
local plr = game.Players.LocalPlayer
local mouse = plr:GetMouse()

mouse.Button1Down:Connect(function()
    print(mouse.Hit.Position)
    local part = Instance.new("Part", workspace)
    local bodyvelocity = Instance.new("BodyVelocity", part)
    bodyvelocity.MaxForce = Vector3.new(math.huge, math.huge,math.huge)
    bodyvelocity.Velocity = mouse.Hit.Position
end)


Right now, if I click somewhere, it goes faster if it is further away. Any way to make it so it will always be a certain speed, lets say 200.

0
CFrame.new(part.Position,mouse.Hit.Position) => Create a CFrame at part position + Point towards mouse position OnaKat 444 — 5y
0
LookVector = Get forward direction. So multiply it with speed OnaKat 444 — 5y

1 answer

Log in to vote
2
Answered by
OnaKat 444 Moderation Voter
5 years ago
Edited 5 years ago

You can use lookVector * speed

Ex. CFrame.new(Part Position , Mouse Position).lookVector * Speed

Script

local plr = game.Players.LocalPlayer
local mouse = plr:GetMouse()

mouse.Button1Down:Connect(function()
    print(mouse.Hit.Position)
    local part = Instance.new("Part", workspace)
    local bodyvelocity = Instance.new("BodyVelocity", part)
    bodyvelocity.MaxForce = Vector3.new(math.huge, math.huge,math.huge)
    bodyvelocity.Velocity = CFrame.new(part.Position,mouse.Hit.Position).lookVector *200
end)
0
Could you explain why you put part.position? Thesquid13 301 — 5y
0
also, What lookvector do I get? Is it both of them added or is it just the parts lookvector? Thesquid13 301 — 5y
Ad

Answer this question