Loveballs, A love2d Softbody lib

Showcase your libraries, tools and other projects that help your fellow love users.
User avatar
ArchAngel075
Party member
Posts: 319
Joined: Mon Jun 24, 2013 5:16 am

Re: Loveballs, A love2d Softbody lib

Post by ArchAngel075 »

Please excuse the double post, but I found a working setRadius implementation, the changes are made directly to my local branch (but not commited the changes yet)

In sense the following should work, just add the following to init.lua :
[As a note, try placing the Sbody:update() in love.update as-well for consistency)

Code: Select all

function Sbody:setRadius(r)
  --brute force method
  
  if not self.dead then
    
    local r = math.max(4,r)
    local x,y = self.sourceBody:getPosition()
    local world = self.world
    local tess = #self.tess or 2;
    
    self.tess = {};
    for i=1, tess do
      self.tess[i] = {};
    end
    
		for i = #self.nodes, 1, -1 do
			self.nodes[i].body:destroy();
			self.nodes[i] = nil;
		end
    
    self.nodes = {}
    
    self.sourceShape:setRadius(r*4)
    
    local nodes = r/2;

    for node = 1, nodes do
      local angle = (2*math.pi)/nodes*node;
      local posx = x+r*math.cos(angle);
      local posy = y+r*math.sin(angle);
      local b = love.physics.newBody(world, posx, posy, "dynamic");
      local f = love.physics.newFixture(b, self.nodeShape);
      f:setFriction(30);
      f:setRestitution(0);
      b:setAngularDamping(50);
		
      local j = love.physics.newDistanceJoint(self.sourceBody, b, posx, posy, posx, posy, true);
      j:setDampingRatio(0.1);
      j:setFrequency(12*(20/r));

      table.insert(self.nodes, {body = b, fixture = f, joint = j});
    end

    for i = 1, #self.nodes do
      if i < #self.nodes then
        local j = love.physics.newDistanceJoint(self.nodes[i].body, self.nodes[i+1].body, self.nodes[i].body:getX(), self.nodes[i].body:getY(),
        self.nodes[i+1].body:getX(), self.nodes[i+1].body:getY(), false);
        self.nodes[i].joint2 = j;
      end
    end

    local i = #self.nodes;
    local j = love.physics.newDistanceJoint(self.nodes[i].body, self.nodes[1].body, self.nodes[i].body:getX(), self.nodes[i].body:getY(),
    self.nodes[1].body:getX(), self.nodes[1].body:getY(), false);
    self.nodes[i].joint3 = j;
    
    self:update()
  end
  
  
end

function Sbody:update()
  if not self.dead then
		local pos = {};
		for i = 1, #self.nodes, self.smooth do
			v = self.nodes[i];
			table.insert(pos, v.body:getX());
			table.insert(pos, v.body:getY());
		end

		tessellate(pos, self.tess[1]);
		for i=1,#self.tess - 1 do
			tessellate(self.tess[i], self.tess[i+1]);
		end
  end
end
Using my PC
[specs]
OS : Windows 7 64
RAM : 8GB
CPU : intel i5 3.20 & 3.60 GHz
GCard : Geforce GTX 650

The hit to FPS while scaling Radius constantly by 1 up and down every love.update() call :
from a radius of ~48 with tess at 1 and smoothing at 1, a constant increase to ~82 at a rate of 1 per frame caused a tank of 38.FPS from a original of 59

decreasing back to ~48 at the same rate brings the FPS up to 59 again,

it seems this affects the radius perfectly without tanking too hard (since i get the same FPS of ~38 if i spawn my player with a radius of 82)

The only issue to arise is that the user can glitch through objects (like a floor) since the nodes will be shifted and created over the floor, but perhaps this should be up to the user to compensate for since its a matter of moving the player as is.

I also have this snippet, since moving the softBody.sourceBody alone using setPosition is messy :

Code: Select all

function Sbody:translate(x,y)
  self.sourceBody:setPosition(self.sourceBody:getX()+x,self.sourceBody:getY()+y)
  for k,v in pairs(self.nodes) do
    v.body:setPosition(v.body:getX()+x,v.body:getY()+y)
  end
end
IndieRetro
Citizen
Posts: 51
Joined: Mon Apr 15, 2013 8:21 pm
Contact:

Re: Loveballs, A love2d Softbody lib

Post by IndieRetro »

S0lll0s wrote:
IndieRetro wrote:

Thanks! Here is my project with it ^^
Hey! that's the teeworlds sun in the background!

Haha! I had teeworlds open in another monitor while making it! :p

What happens to be your teeworlds name? Chances are I've played with you at some point, I've been playing Teeworlds every day for the past 7 years :p
Last edited by IndieRetro on Mon Jan 26, 2015 11:05 am, edited 2 times in total.
irc.freenode.org ##oodnet
http://exez.in/
IndieRetro
Citizen
Posts: 51
Joined: Mon Apr 15, 2013 8:21 pm
Contact:

Re: Loveballs, A love2d Softbody lib

Post by IndieRetro »

ArchAngel075 wrote:Please excuse the double post, but I found a working setRadius implementation, the changes are made directly to my local branch (but not commited the changes yet)
Hey, thanks for all the fixes and suggestions. I am not activly working on this lib at the moment, but once I come back to re-write it I will consider all of your changes & fixes :)
irc.freenode.org ##oodnet
http://exez.in/
User avatar
ArchAngel075
Party member
Posts: 319
Joined: Mon Jun 24, 2013 5:16 am

Re: Loveballs, A love2d Softbody lib

Post by ArchAngel075 »

Okay, that explains haha.

Well ill make changes and update my fork for anyone who wants to have a slightly derpier version with experimental code.

Though the effects your basic lib achieves can be useful for making one really neat screen saver too!

Thanks for the lib, and also...

~TEEWORLDS!~ :halloween:
User avatar
s-ol
Party member
Posts: 1077
Joined: Mon Sep 15, 2014 7:41 pm
Location: Cologne, Germany
Contact:

Re: Loveballs, A love2d Softbody lib

Post by s-ol »

IndieRetro wrote:
S0lll0s wrote:
IndieRetro wrote:

Thanks! Here is my project with it ^^
Hey! that's the teeworlds sun in the background!

Haha! I had teeworlds open in another monitor while making it! :p

What happens to be your teeworlds name? Chances are I've played with you at some point, I've been playing Teeworlds every day for the past 7 years :p
I think my name was mostly S0lll0s or W33D|S0lll0s... though I don't exactly remember, been a while. I was hardcore-playing teeworlds something like 4 (5? 6?) years ago and then had a smaller phase again about a year back.

s-ol.nu /blog  -  p.s-ol.be /st8.lua  -  g.s-ol.be /gtglg /curcur

Code: Select all

print( type(love) )
if false then
  baby:hurt(me)
end
IndieRetro
Citizen
Posts: 51
Joined: Mon Apr 15, 2013 8:21 pm
Contact:

Re: Loveballs, A love2d Softbody lib

Post by IndieRetro »

ArchAngel075 wrote:Okay, that explains haha.

Well ill make changes and update my fork for anyone who wants to have a slightly derpier version with experimental code.

Though the effects your basic lib achieves can be useful for making one really neat screen saver too!
Update released, re-worked a lot of the code, implemented some of the things you have done on your fork, cleaned up code and added comments! ^^
irc.freenode.org ##oodnet
http://exez.in/
Connorses
Citizen
Posts: 63
Joined: Fri Sep 06, 2013 7:02 am

Re: Loveballs, A love2d Softbody lib

Post by Connorses »

OH MAN THIS IS SO COOL

It immediately reminded me of Gish (which is a game I highly recommend by the way). It makes me want to try and clone Gish's mechanics. It would be an interesting experiment...

Most of it would surprisingly easy, since I can adjust the Frequency to make a blob jump, and also the friction and density (Gish can change his physical properties when you hold down certain buttons). The hard one would be the "sticky key" where you can stick to objects and climb walls, because the blob has to un-stick if it's pulled with too much force. Looks like I could conceivably do this with joints!

EDIT: I think I could figure this out, but I would need a way to listen to the collisions for all the chain links. I'll look into it more tomorrow.
IndieRetro
Citizen
Posts: 51
Joined: Mon Apr 15, 2013 8:21 pm
Contact:

Re: Loveballs, A love2d Softbody lib

Post by IndieRetro »

Connorses wrote:OH MAN THIS IS SO COOL

It immediately reminded me of Gish (which is a game I highly recommend by the way). It makes me want to try and clone Gish's mechanics. It would be an interesting experiment...

Most of it would surprisingly easy, since I can adjust the Frequency to make a blob jump, and also the friction and density (Gish can change his physical properties when you hold down certain buttons). The hard one would be the "sticky key" where you can stick to objects and climb walls, because the blob has to un-stick if it's pulled with too much force. Looks like I could conceivably do this with joints!

EDIT: I think I could figure this out, but I would need a way to listen to the collisions for all the chain links. I'll look into it more tomorrow.

Sticky blob you say? I've done that one ^^ https://www.youtube.com/watch?v=3IBy2uyvVHY

What I did was create a distance joint for each outside node to whatever that node was touching, and change the frequency/damping of that node depending on how far the player pulls from it and what-not, works pretty well.
irc.freenode.org ##oodnet
http://exez.in/
User avatar
ArchAngel075
Party member
Posts: 319
Joined: Mon Jun 24, 2013 5:16 am

Re: Loveballs, A love2d Softbody lib

Post by ArchAngel075 »

been on a offput with my game, but seeing that sticky feature makes me want to attempt my own version for when the player absorbs tar/oil like substances...

Ill also be grinding away at making my setRadius function not have the player warp through object. Probably by shifting existing nodes outwards and adding nodes between during growth, and removing nodes and shifting nodes inwards for shrinking. This way the existing nodes whom are already tracked will simply push the softBody, which would also make for a more proper appearing growth/shrink perhaps.

Although my current setRadius unction is decent to prevent warping through other objects if the rate of change is low.
Connorses
Citizen
Posts: 63
Joined: Fri Sep 06, 2013 7:02 am

Re: Loveballs, A love2d Softbody lib

Post by Connorses »

EDIT EDIT EDIT:

I solved one problem, now I have new one. :megagrin:
Last edited by Connorses on Tue Feb 03, 2015 6:44 am, edited 1 time in total.
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 2 guests