1waffle1
|
  |
| Joined: 16 Oct 2007 |
| Total Posts: 16381 |
|
|
| 19 Jul 2011 01:27 PM |
I made a physics engine 'cus I was bored. Test it here. You can turn on/off collision by saying "collision" http://www.roblox.com/Orbital-physics-testing-item?id=31314964
Here's the source:
for _, v in ipairs(workspace:GetChildren()) do if v:findFirstChild("Force") then v.Parent = workspace.Game end end
local slow = 3 local collision = true
game.Players.PlayerAdded:connect(function(p) p.Chatted:connect(function(msg) if msg:lower() == ("collision"):sub(1, #msg) then collision = not collision end end) end)
-- Physics engine while wait() do for _, a in ipairs(workspace.Game:GetChildren()) do if a.Name ~= "Part2" then a.CFrame = a.CFrame + a.Force.Value/slow for _, b in ipairs(workspace.Game:GetChildren()) do if a ~= b then if (a.Position - b.Position).magnitude < (a.Size.X/2 + b.Size.X/2) and collision then local fa, fb = a.Force.Value, b.Force.Value if b.Name ~= "Part2" then a.Force.Value, b.Force.Value = fb*(b.Size.X/a.Size.X), fa*(a.Size.X/b.Size.X) else a.Force.Value = a.Force.Value + CFrame.new(b.Position, a.Position).lookVector*(a.Force.Value.X^2 + a.Force.Value.Y^2 + a.Force.Value.Z^2)^(1/3) end a.CFrame = b.CFrame + CFrame.new(b.Position, a.Position).lookVector*(a.Size.X/2 + b.Size.X/2) end a.Force.Value = a.Force.Value + CFrame.new(a.Position, b.Position).lookVector/math.max((a.Position - b.Position).magnitude/2, 1)/slow*(b.Size.X/a.Size.X) end end end end end
|
|
|
| Report Abuse |
|
|
1waffle1
|
  |
| Joined: 16 Oct 2007 |
| Total Posts: 16381 |
|
|
| 19 Jul 2011 01:40 PM |
| Now steal my physics engine and make something more interesting out of it. |
|
|
| Report Abuse |
|
|
Megolas
|
  |
| Joined: 16 Jan 2011 |
| Total Posts: 357 |
|
|
| 19 Jul 2011 02:02 PM |
Say, i thought about it, we could use the 2 formulas: 1) X = X0 + V0t + 0.5at^2 2) v = V0 + at
to make a non lagging physics engine, but when something fall, how do we calculate how far will it bump up? (i the material changes it, but still, how?) |
|
|
| Report Abuse |
|
|
1waffle1
|
  |
| Joined: 16 Oct 2007 |
| Total Posts: 16381 |
|
| |
|
| |
|
|
| 19 Jul 2011 04:57 PM |
| Trivial physics. YOU should make them work as boxes, not spheres. |
|
|
| Report Abuse |
|
|
Megolas
|
  |
| Joined: 16 Jan 2011 |
| Total Posts: 357 |
|
|
| 20 Jul 2011 08:05 AM |
| ... i knew that - but what is the formula to calculate how far will it jump? |
|
|
| Report Abuse |
|
|