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

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

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)

1 comment

0

I think this is done using lookVector. I have no clue how to use it so maybe you can search it up!

1 answer

✓ Accepted answer

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))

1 comment

0

Thanks man

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