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