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

Have velocity change based on where part is facing? [Solved]

Hi, I have been trying to create a cannon which launches physics based parts, but have run into issues with cloned part's velocities not moving them in the direction i want them to:

Issue GIF

Current code which clearly does not work:

local model = script.Parent

local function fire()
	local newball = workspace.Ball:Clone()
	newball.Parent = workspace.Storage
	newball.Position = model.Fire.Position
	newball.Velocity = model.Fire.Orientation
end

model.Activated:Connect(fire)

Fire is the floating green part in front of the cannon in the issue gif

So, how do i have the ball's velocity move in the direction the green part is facing (forward) regardless of orientation?

1 answer

For people of the future, i worked it out.

my solution was to set the newball.Velocity to the CFrame.LookVector of the Fire part, which faces forward / at the front, and multiply it by the chosen velocity:

local velocity = 500 -- you can change this to whatever you want, higher is faster, lower is slower
newball.Velocity = model.Fire.CFrame.LookVector * velocity

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