#Weird movements with applied forces

1 messages · Page 1 of 1 (latest)

dire nimbus
#

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)
olive schooner
dire nimbus
olive schooner
dire nimbus
#

Uh

#

How can i explain this

#

Simplified formula for magnus effect is
F = S(w * v)

Where
w is a angular velocity of an object
v is a Velocity of an object
And S is a scalar that depends on fluid density etc

#

Cross product is used to ensure that forces for spin and motion and perpendicular

#

Just stupid right hand rule that happends to be everywhere in physics because vectors are upside down

olive schooner
dire nimbus
#

Should is set to Attachment0?

#

Should i*

olive schooner
#

coz maybe that formula already accounts for rotation im not sure

#

can't hurt to try both

dire nimbus
#

I mean

#

Thing i noticed that Roblox physics engine is ass

#

If i apply linear Velocity and angular velocity throught properties its movement is pretty wild

#

Maybe my approach is wrong, or Roblox physics engine is ass to simulate those kind of things

olive schooner
#

no your formula is more likely wrong

olive schooner
#

applyforce at center

#

i suggest you debug that formula so you can see the outputs it is giving

#

like ballsocket the ball to an anchored part and let it spin in place then add another part (or just spam print every frame) to see the output

#

then mess with its properties to make sure it's working how you intended

#

odds are good your formula is simply wrong

#

i've never worked with this effect before so i couldn't tell you exactly without doing all that research myself, but i would most likely end up doing this anyway

dire nimbus
#

Just apply on a sphere angular velocity and linear velocity and you will see what happends

olive schooner
#

without doing all that research myself, i would most likely end up doing <debugging technique> anyway
yeah totally means i'm going to check this all by myself

#

as if i dont have anything better to do

dire nimbus
#

😭

olive schooner
# dire nimbus 😭

you should be capable of making some visualizers for this and physics debugging...

olive schooner
dire nimbus
#

That's what im doing rn

dire nimbus
#

I had to tweak them a lil bit

#

Turns out i can just simply get velocity of an object and use cross product on Gravity