Deactivating physics objects?

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
gladius2metal
Prole
Posts: 26
Joined: Thu Nov 22, 2012 2:08 am

Deactivating physics objects?

Post 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?
User avatar
Przemator
Party member
Posts: 107
Joined: Fri Sep 28, 2012 6:59 pm

Re: Deactivating physics objects?

Post 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 )
User avatar
gladius2metal
Prole
Posts: 26
Joined: Thu Nov 22, 2012 2:08 am

Re: Deactivating physics objects?

Post 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
User avatar
Przemator
Party member
Posts: 107
Joined: Fri Sep 28, 2012 6:59 pm

Re: Deactivating physics objects?

Post 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.
Knaimhe
Prole
Posts: 34
Joined: Mon Jan 23, 2012 7:23 pm

Re: Deactivating physics objects?

Post 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.
User avatar
gladius2metal
Prole
Posts: 26
Joined: Thu Nov 22, 2012 2:08 am

Re: Deactivating physics objects?

Post by gladius2metal »

Knaimhe wrote:You're probably looking for this.
https://love2d.org/wiki/Body:setActive
thx!!!
In other news I am blind...
Post Reply

Who is online

Users browsing this forum: No registered users and 4 guests