I’m just trying to make a part move in a straight line away from the player (like a fireball blast) and cant figure it out.
I’ve looked through the wiki, the forums, and on youtube but can’t find anything that explains it clearly.
I’m just trying to make a part move in a straight line away from the player (like a fireball blast) and cant figure it out.
I’ve looked through the wiki, the forums, and on youtube but can’t find anything that explains it clearly.
To use the linear velocity, you need add an attachment inside the part as well have a linear velocity and then get the attachment0 property to that attachment, then from there you can mess with the properties. A tip is to have your parts massless so that it doesn’t affect the velocity too much with the heavy mass
Linear velocity requires an attachment. To use it, you first have to insert an attachment in the part you want to move and then set the LinearVelocity.Attachment0 to that attachment.
A simple example can be:
-- you need to define the player first
local HRP = player.Character.HumanoidRootPart
local Part = Instance.new("Part", workspace) -- the part to move
Part.CFrame = HRP.CFrame * CFrame.new(0,0,-3) -- Putting the part infront of the player
local Attachment = Instance.new("Attachment", Part) -- the attachment used in Linearvelocity
local LV = Instance.new("LinearVelocity", Attachment) -- creating the linear velocity
LV.MaxForce = math.huge -- no need to worry about this
LV.VectorVelocity = HRP.CFrame.lookVector * 100 -- change 100 with how fast you want the projectile to go
LV.Attachment0 = Attachment -- setting the attachment
game.Debris:AddItem(Part, 2) -- deletes the moving part after 2 second
why is active greyed out and i cannot click it on LinearVelocity i have attachment and setup correctly
I think active is a read-only property or is always active
its actully not CFrame.new that you have to use but Vector3.new or else it wont work
updated version:
-- you need to define the player first
local HRP = player.Character.HumanoidRootPart
local Part = Instance.new("Part", workspace) -- the part to move
Part.Position = HRP.CFrame * Vector3.new(0,0,-3) -- Putting the part infront of the player
local Attachment = Instance.new("Attachment", Part) -- the attachment used in Linearvelocity
local LV = Instance.new("LinearVelocity", Attachment) -- creating the linear velocity
LV.MaxForce = math.huge -- no need to worry about this
LV.VectorVelocity = HRP.CFrame.lookVector * 100 -- change 100 with how fast you want the projectile to go
LV.Attachment0 = Attachment -- setting the attachment
game.Debris:AddItem(Part, 2) -- deletes the moving part after 2 second
You can’t multiply Vector3
and CFrame
.
It also it not neccessary, it still works in the new version.
Plus please do not necropost.
“noooo you just necroposted!” -
For anyone in the future who stumbles upon this, you can, in fact, multiply vectors and CFrames together, although Jorjack00’s “update” would still serve no purpose
(For anyone who says “nooo dont necropost,” roblox specifically states "Only reply if you have additional details, which I do in fact have, as I’m clearing up some misinformation that has been previously posted in this topic.)
CFrame * Vector3: Produces a Vector3 transformed from object to world coordinates.
To my knowledge it is a relatively new feature. I remember getting errors from multiplying them.
You can use a more simpler version of using velocity, using the AssemblyLinearVelocity
property in every part.
local part = workspace.Part
task.wait(10)
part.AssemblyLinearVelocity = Vector3.new(0,10000,0) --The part should shoot upwards
You don’t need to go through the trouble of adding attachments and slight math in your script.
I haven’t had any issue at all, and I’ve been using it for a quite bit now. If it was causing issues before, then it was probably fixed since you last used it.
It’s not working for me. I’m trying to use this code with a ball, but it just go to a random direction. Do you happen to know what is happening? And is there a way to the ball go to where the mouse is?
Hi,
LinearVelocity is a bit hard to figure out, i recommend you use BodyVelocity [deprecated but still works]. Velocity that depends on mouse could be done by sending a message from client to server via RemoteEvent [To make it serverside] or by making localscript, which makes ball move only for player [clientside].