BodyVelocity.MaxForce = part.CFrame:VectorToObjectSpace(Vector3.new(0,((workspace.Gravity)*GetModelMass(plr)*(math.pow(2,math.tan(MovementPower*.4999*math.pi))))))
BodyVelocity.Velocity = part.CFrame:VectorToObjectSpace(Vector3.new(0,MovementSpeed))
Im basically just trying to make a force go relative to the orientation of the part.
For example, if I want to move it up, then I turn the part 90 degrees along the x axis. Now it should act positive along the z axis.
It doesn’t work for all rotations, why?
Heres the full script I’m currently using
local Direction = "Horizontal"
local MovementSpeed = 30 -- Speed at which it moves (positive is forwards/up)
local NormalSpeed = 80 -- Speed at which to show the normal scrolling texture
local IdleSpeed = 30 -- Speed at which to show force field
local MovementPower = 0.75 -- scale from -1 to 1 based on how much control the player has to move against the force. 0 means equal force, 1 means player cannot move against, -1 means force doesn't effect player
-- Recommended to set at .75 I definitely would not set at one
CreateVerticalTexture(ForcefieldImage,IdleTransparencyHorizontal)
part.Touched:Connect(function(partTouched)
if partTouched.Parent and game.Players:FindFirstChild(partTouched.Parent.Name) then
local plr = partTouched.Parent
if not PlayersTouching[plr] then
PlayersTouching[plr] = partTouched
local RootPart = plr.LowerTorso
local connect1
connect1 = part.TouchEnded:Connect(function(part)
if part == PlayersTouching[plr] then
connect1:Disconnect()
PlayersTouching[plr] = nil
if RootPart and RootPart:FindFirstChild("SpeedyBlockVelocity") then
RootPart.SpeedyBlockVelocity:Destroy()
end
end
end)
local BodyVelocity = Instance.new("BodyVelocity", RootPart)
BodyVelocity.Name = "SpeedyBlockVelocity"
BodyVelocity.MaxForce = part.CFrame:VectorToWorldSpace(Vector3.new(((plr.Humanoid.WalkSpeed)*GetModelMass(plr)*(math.pow(2,math.tan(MovementPower*.4999*math.pi)))),((workspace.Gravity)*GetModelMass(plr)*(math.pow(2,math.tan(MovementPower*.4999*math.pi)))),((plr.Humanoid.WalkSpeed)*GetModelMass(plr)*(math.pow(2,math.tan(MovementPower*.4999*math.pi))))))
local TargetRelativeVelocity = part.CFrame:VectorToWorldSpace(Vector3.new(MovementSpeed))
while RS.Stepped:Wait() do
if plr and BodyVelocity and plr.Humanoid and plr.Humanoid.Health>0 then
BodyVelocity.Velocity = TargetRelativeVelocity
else
if BodyVelocity then BodyVelocity:Destroy() break end
end
end
end
end
end)```