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

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

Asked by 4 years ago
Edited by DeceptiveCaster 4 years ago

This question has been solved by the original poster.

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

Log in to vote
2
Answered by 4 years ago

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
Ad

Answer this question