How to rotate AssemblyAngularVelocity Vector?

Hello!

I have an example place included of kicking a ball that curves left, right, back or top using the magnus formula.

However, I cannot get the magnus force of the ball, and the spin of the ball to go in the same direction.

For example, if I curve the ball to the left, it curves to the left but the ball has a back spin and not a left spin. I assume the solution is to somehow rotate the angular velocity vector that I set, but I’ve been stuck for days, tried everything and cannot figure out how to get it working.

Any help would be greatly appreciated thank you!

Curve Ball Devforum.rbxl (39.7 KB)

local ballObject = script.Parent:WaitForChild("Handle")
local tool = script.Parent

local player = game:GetService("Players").LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local HRP = character:WaitForChild("HumanoidRootPart")
local mouse = player:GetMouse()

--Left means the ball spins to the left but it doesn't actually curve to the left
local curveAngles = {
	["Right"] = CFrame.Angles(math.rad(90), math.rad(0), 0), --Spins right, but does a backspin curve
	["Left"] = CFrame.Angles(math.rad(-90), math.rad(0), 0), --Spins left, but does a topspin curve
	["Top"] = CFrame.Angles(math.rad(0), math.rad(90), 0), --Spins top, but does a left curve
	["Back"] = CFrame.Angles(math.rad(0), math.rad(-90), 0), --Spins back, but does a right curve
}

local ball

game["Run Service"].Heartbeat:Connect(function(dt)
	if ball ~= nil then
		if ball.AssemblyLinearVelocity.Magnitude > 0 then
			local v = ball.AssemblyLinearVelocity
			local vs = ball.AssemblyAngularVelocity
			local s = 1
		
			local magnus = s * (vs * ball.AssemblyMass)
			ball.MagnusForce.Force = magnus
		end
	end
end)

mouse.Button1Down:Connect(function()
	--Sets ball kick direction
	local upAngle = CFrame.Angles(math.rad(40), 0, 0)
	local direction = (HRP.CFrame * upAngle).LookVector
	
	--Sets ball power
	local power = 120 * direction

	--Clone ball and set position
	local ballPosition = HRP.CFrame * Vector3.new(0, 2, -2)
	ball = ballObject:Clone()
	ball.CFrame = CFrame.new(ballPosition)
	ball.CanCollide = true
	ball.Parent = game.Workspace
	
	--Set velocity
	ball.AssemblyLinearVelocity = power
	
	--Set curve direction and set angular velocity
	local curveDirectionName = "Top"
	ball.AssemblyAngularVelocity = (HRP.CFrame * curveAngles[curveDirectionName]).LookVector * 50
end)
1 Like