I wanted to "recreate" magnus effect using built-in physics engine but everytime i apply LinearVelocity and AngularVelocity at the same it ball weirdly dances in the air, and i cant really control it.
(Please ignore how my code is messy. Im just playing around!)
local RepStorage = game:GetService("ReplicatedStorage")
local RunService = game:GetService("RunService")
local Debris = game:GetService("Debris")
local part: Part = script.Parent
local Coefficent = .8
local Balls = {}
local cd = false
local _angle = math.rad(60)
local _power = 120
local _velocity = Vector3.new(-math.cos(_angle), math.sin(_angle), 0) * _power
part.Touched:Connect(function(Part: Part)
local Player: Player = game.Players:GetPlayerFromCharacter(Part.Parent)
if not Player then end
if cd then return end
task.delay(3,function()
cd = false
end)
cd = true
local Ball = RepStorage.Ball:Clone()
Ball.Parent = workspace
Ball.PrimaryPart.Position = part.Position + Vector3.new(-5, 0, 0)
local VectForce: VectorForce = Ball:FindFirstAncestorOfClass("VectorForce")
Ball.PrimaryPart.AssemblyLinearVelocity = _velocity
Ball.PrimaryPart.AssemblyAngularVelocity = Vector3.new(20, 0, 0)
table.insert(Balls, Ball)
Debris:AddItem(Ball, 3)
end)
RunService.Heartbeat:Connect(function(Delta: number)
for _, Ball in pairs(Balls) do
local p = Ball.PrimaryPart
if not p or not p.Parent then continue end
local vf = p:FindFirstChildOfClass("VectorForce")
if not vf then continue end
local v = p.AssemblyLinearVelocity
local w = p.AssemblyAngularVelocity
local F = w:Cross(v) * Coefficent
vf.Force = F
end
end)