Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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.

2 comments

0

CFrame.new(part.Position,mouse.Hit.Position) => Create a CFrame at part position + Point towards mouse position

0

LookVector = Get forward direction. So multiply it with speed

1 answer

✓ Accepted answer

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)

2 comments

0

Could you explain why you put part.position?

0

also, What lookvector do I get? Is it both of them added or is it just the parts lookvector?

This discussion is preserved as it was. New answers, comments, and votes are closed.