Page 1 of 1

Deactivating physics objects?

Posted: Mon Nov 26, 2012 7:07 pm
by gladius2metal
I looked at the API for deactivating a physics object, but couldn't find anything. (No detaching from world, no deactivating in body etc.)
Is there a way to deactivate and reactivate physics objects easily? (E.g. like with graphics just no drawing them for a while.)

Background:
I have spaceships docking to a space station, thus they should despawn and later respawn.
Is there any other possibility besides destroying the physics object and later recreating it?

Re: Deactivating physics objects?

Posted: Mon Nov 26, 2012 10:23 pm
by Przemator
I think bodies automatically go to sleep when not moving.

You may have to enable sleeping though:

world = love.physics.newWorld( xg, yg, sleep )

Body:setSleepingAllowed( allowed )

If you want to disable collisions for a body, you could try this:

Fixture:setSensor( sensor )

Re: Deactivating physics objects?

Posted: Mon Nov 26, 2012 10:31 pm
by gladius2metal
Przemator wrote:I think bodies automatically go to sleep when not moving.
that was my first thought but:
https://love2d.org/wiki/Body:putToSleep
Removed in LÖVE 0.8.0
This method is not supported in that and later versions.
also:
"A sleeping body is much more efficient to simulate than when awake.
If sleeping is allowed, a body that has come to rest will sleep. "
seems to me that sleeping is actually not deactivated
Przemator wrote: If you want to disable collisions for a body, you could try this:
Fixture:setSensor( sensor )
ahh nice, didn't know that

Re: Deactivating physics objects?

Posted: Mon Nov 26, 2012 11:19 pm
by Przemator
Until you actually reach a problem with the simualtion being too heavy, I suggest not to think about it. As I've said, if you enable sleeping, it should be handled automatically.

Re: Deactivating physics objects?

Posted: Tue Nov 27, 2012 1:11 am
by Knaimhe
You're probably looking for this.
https://love2d.org/wiki/Body:setActive

And when you draw, use this (if statement).
https://love2d.org/wiki/Body:isActive

Code: Select all

blah blah
if body:isActive() then
  draw dat body
end
bluh blargh
If that doesn't work, the oldschool nublet solution of setting the collision mask of the shapes involved to er'rythin' also works. You can simply reset them later.
You may also want to set the mass to zero. *shrug*
As long as the space station is static, you shouldn't have to deal with mass.

Re: Deactivating physics objects?

Posted: Tue Nov 27, 2012 1:26 am
by gladius2metal
Knaimhe wrote:You're probably looking for this.
https://love2d.org/wiki/Body:setActive
thx!!!
In other news I am blind...