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

how do i set a parts velocity with coordinates relative to another part?

Asked by 4 years ago

Hey, im working on a gun and im trying make a shell come out the gun when i fire. The shells Velocity property is then set so it looks like its being ejected from the gun but the shell moves relative to the world so it doesnt look right unless my character is facing north, so for example, if i face south the shell looks like its being thrown out of the other side of the gun. I cant figure out how to set the shell velocity co ords relative to the gun and need help. Here is the code before i started messing with it.

replicatedStorage.glockEvents.FireEvent.OnServerEvent:Connect(slidePosition)
local serverShell = replicatedStorage.glockAnimations.Shell
local clonedShell = serverShell:Clone()
clonedShell.Parent = workspace
clonedShell.CFrame = slidePosition
clonedShell.Velocity =  Vector3.new(10,8,0)

slidePosition is sent from this local script

local tool = script.Parent
local slide = tool.Model["Slide"]
local slidePosition = slide.CFrame
fireEvent:FireServer(slidePosition)
0
I think this is done using lookVector. I have no clue how to use it so maybe you can search it up! Arj783 72 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago

You can use the CFrame:VectorToWorldSpace() function you convert a vector from object to world space. It’s usage is fairly simple:


replicatedStorage.glockEvents.FireEvent.OnServerEvent:Connect(slidePosition) local serverShell = replicatedStorage.glockAnimations.Shell local clonedShell = serverShell:Clone() clonedShell.Parent = workspace clonedShell.CFrame = slideCFrame -- Please name variables better, slidePosition suggests a Vector3 type clonedShell.Velocity = slideCFrame:VectorToWorldSpace(Vector3.new(10,8,0))
0
Thanks man StarDestroy 25 — 4y
Ad

Answer this question