Hey,
So I added the Magnus effect to the ball entity in a gamemode that I'm developing, and I figured I'd share some of what I learned.
I made a short video discussing this:
[video]https://youtu.be/d-no_tkUtns[/video]
and here's my actual source code for the effect:
[CODE]
local magnus_effect_strength = 2.5
function ENT:PhysicsUpdate(phys)
// Here we simulate the magnus effect, which creates a force on the ball when it has a spin and it's experiencing wind.
local spin = phys:GetAngleVelocity()
local rot_spin = spin*1.0
local angle = phys:GetAngles()
rot_spin:Rotate(angle)
local wind_force = -phys:GetVelocity()
local pos = self:GetPos()
//debugoverlay.Line( pos, pos+rot_spin, engine.TickInterval()*2, Color(255,128,0), true)
//debugoverlay.Line( pos, pos+wind_force, engine.TickInterval()*2, Color(0,128,255), true)
if not rot_spin:IsZero() and not wind_force:IsZero() then
local magnus_force = -(rot_spin:Cross(wind_force))
local magnus_length = magnus_force:Length()
phys:AddAngleVelocity(-spin*magnus_length*0.00000000175*magnus_effect_str ength)
//debugoverlay.Line( pos, pos+cross, engine.TickInterval()*2, Color(0,255,0), true)
phys:AddVelocity(magnus_force*0.000005*magnus_effe ct_strength)
end
end
[/CODE]
I would have made it a 100% accurate simulation, but I'm afraid that's a bit beyond me.
[editline]30th September 2016[/editline]
FFFF, it keeps putting spaces inside of my variable!
Wow...I really loved your explanation! Pretty awesome
[QUOTE=gonzalolog;51133823]Wow...I really loved your explanation! Pretty awesome[/QUOTE]
Thanks ^u^
This was a great tutorial. Really enjoyed it. Not sure if you've worked out all of the physics yet, ball just seems a little on the heavy side compared to RL, but I love this. Keep up the good work.
Really cool! Loved the explanation too. But it seems a bit odd that after being shot up and brought down by magnus force, it doesn't jump back up (As seen at ~5:00)
[QUOTE=JasonMan34;51136808]Really cool! Loved the explanation too. But it seems a bit odd that after being shot up and brought down by magnus force, it doesn't jump back up (As seen at ~5:00)[/QUOTE]
I don't see what you're seeing. I kicked the ball a couple of times, try watching that part again but slowed down and keep an eye on my vehicle and/or my fuel gauge at the bottom-left.
I'm really excited at how this adds several improved dynamics to gameplay, the fact it has downforce and has good, straight, low control for an attacker while it will simultaneously pop straight into the air if that gets deflected and let everyone kind of scramble for it again is really solid
[QUOTE=JasonMan34;51136808]Really cool! Loved the explanation too. But it seems a bit odd that after being shot up and brought down by magnus force, it doesn't jump back up (As seen at ~5:00)[/QUOTE]
it's still rolling forward and has down-force, and didn't fall from a great height
Great stuff dude, is this gamemode running on a public server? I would like to try this out.
Enjoyed watching it, learned some good stuff from this video.. GJ man
A lovely and informative explanation of something you won't really find a tutorial on anywhere else. I quite enjoyed the different approach to displaying the code rather than the standard recorded text-editor.
In future videos, it may be worth using scientific notation for those small numbers rather than repeating n amount of 0's
[QUOTE=CosmicSeagull;51143422]A lovely and informative explanation of something you won't really find a tutorial on anywhere else. I quite enjoyed the different approach to displaying the code rather than the standard recorded text-editor.
In future videos, it may be worth using scientific notation for those small numbers rather than repeating n amount of 0's[/QUOTE]
But I like repeating zero :v:
EDIT: In all seriousness, I would have gone with scientific notation, but this isn't simple to implement in most coding languages. I keep my code minimal, even if that means having to type a really long literal.
[QUOTE=raubana;51143668]But I like repeating zero :v:
EDIT: In all seriousness, I would have gone with scientific notation, but this isn't simple to implement in most coding languages. I keep my code minimal, even if that means having to type a really long literal.[/QUOTE]
Actually lua supports writing numbers with scientific notation. For example, you can write 0.0025 as 2.5e-3, or in your case, you can write your products as 5e-6 and 1.75e-9.
[QUOTE=Metamist;51170652]Actually lua supports writing numbers with scientific notation. For example, you can write 0.0025 as 2.5e-3, or in your case, you can write your products as 5e-6 and 1.75e-9.[/QUOTE]
I'll keep that in mind - I had no idea that was even possible in lua.
[QUOTE=raubana;51171077]I'll keep that in mind - I had no idea that was even possible in lua.[/QUOTE]
It's possible in pretty much every programming language that has floating point numbers.
Sorry, you need to Log In to post a reply to this thread.