Weightless Physics object
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
- bartbes
- Sex machine
- Posts: 4946
- Joined: Fri Aug 29, 2008 10:35 am
- Location: The Netherlands
- Contact:
Re: Weightless Physics object
That is very much a bug, feel free to report it.
- ghostwriter
- Prole
- Posts: 38
- Joined: Sat Dec 11, 2010 11:08 pm
Re: Weightless Physics object
Reported, Issue #167
- tentus
- Inner party member
- Posts: 1060
- Joined: Sun Oct 31, 2010 7:56 pm
- Location: Appalachia
- Contact:
Re: Weightless Physics object
The solution by ghostwriter indeed works, and is now used in multiple places in Kurosuke! Thanks man!
Kurosuke needs beta testers
- kikito
- Inner party member
- Posts: 3153
- Joined: Sat Oct 03, 2009 5:22 pm
- Location: Madrid, Spain
- Contact:
Re: Weightless Physics object
I've done some research on this.
There's an issue to update box2d to 2.1.x, but it's on hold.
By looking at the box2d source code currently used in LÖVE, it seems that there are only two kinds of bodies: "static" and "dynamic". A body is labelled as "static" if both the inverses of its mass and inertia are 0.
So I tried creating an object with mass=0 and inertia=not-0, and managed to move the object a bit, but it only moved when it hit other objects, and not in the direction that I wanted. Press any key and while the two bodies collide to see the effect:
I doubt this could be used for making platforms, though.
Actually, Box2D has been able to move objects with 0 mass for some time:Robin wrote:Zero mass is static for Box2D. But can't you just set a very low mass instead? After all, even light has mass (albeit practically 0).
It's just that the version bundled with LÖVE is from before kinematic bodies were included. Which is a shame, because kinematic bodies seem exactly what tentus needs for his platforms.b2_kinematicBody
A kinematic body moves under simulation according to its velocity. Kinematic bodies do not respond to forces. They can be moved manually by the user, but normally a kinematic body is moved by setting its velocity. A kinematic body behaves as if it has infinite mass, however, Box2D stores zero for the mass and the inverse mass. Kinematic bodies do not collide with other static or kinematic bodies.
There's an issue to update box2d to 2.1.x, but it's on hold.
By looking at the box2d source code currently used in LÖVE, it seems that there are only two kinds of bodies: "static" and "dynamic". A body is labelled as "static" if both the inverses of its mass and inertia are 0.
So I tried creating an object with mass=0 and inertia=not-0, and managed to move the object a bit, but it only moved when it hit other objects, and not in the direction that I wanted. Press any key and while the two bodies collide to see the effect:
Code: Select all
function love.load()
world = love.physics.newWorld(0, 0, 800, 600)
world:setGravity(0, 10)
body1 = love.physics.newBody(world, 200, 200, 0, 1)
shape1 = love.physics.newRectangleShape(body1, -20, -20, 40, 20)
body2 = love.physics.newBody(world, 200, 50)
shape2 = love.physics.newRectangleShape(body2, -10, -10, 20, 20)
body2:setMassFromShapes()
end
function love.draw()
love.graphics.polygon("fill", shape1:getPoints())
love.graphics.polygon("line", shape2:getPoints())
if pressed then
love.graphics.print("Pressed", 8, 8)
end
if body1:isStatic() then
love.graphics.print("Static", 8,20)
end
end
function love.update(dt)
if pressed then body1:setLinearVelocity(10, 0) end
world:update(dt)
end
function love.keypressed(key, unicode)
pressed = true
end
When I write def I mean function.
- Taehl
- Dreaming in associative arrays
- Posts: 1025
- Joined: Mon Jan 11, 2010 5:07 am
- Location: CA, USA
- Contact:
Re: Weightless Physics object
As an alternate solution: What if you made a large, invisible box that nothing except the platform collides with. Then you just slide your platform around on top of it. Since the player can't touch or see it, they'd never know it was there.
Earliest Love2D supporter who can't Love anymore. Let me disable pixel shaders if I don't use them, dammit!
Lenovo Thinkpad X60 Tablet, built like a tank. But not fancy enough for Love2D 0.10.0+.
Lenovo Thinkpad X60 Tablet, built like a tank. But not fancy enough for Love2D 0.10.0+.
- tentus
- Inner party member
- Posts: 1060
- Joined: Sun Oct 31, 2010 7:56 pm
- Location: Appalachia
- Contact:
Re: Weightless Physics object
Because that locks you to a single horizontal axis. Platforms can move up and down, or at angles. If I was shooting for just left-to-right, I'd just use body:setY() every frame, using the starting Y position.Taehl wrote:As an alternate solution: What if you made a large, invisible box that nothing except the platform collides with. Then you just slide your platform around on top of it. Since the player can't touch or see it, they'd never know it was there.
Actually, how would you do a box that only collides with platforms? Toggle its sensorness on every collision?
I also have other floating objects, such as birds (well, microbes that float, but lets call them birds). Platforms were the simplest example of a weightless object.
@kikito:
You make me sad, knowing that the perfect solution is just out of reach. Ah well, maybe in a future version of Love.
Kurosuke needs beta testers
- Robin
- The Omniscient
- Posts: 6506
- Joined: Fri Feb 20, 2009 4:29 pm
- Location: The Netherlands
- Contact:
Re: Weightless Physics object
No, use shape:setMask().tentus wrote:Actually, how would you do a box that only collides with platforms? Toggle its sensorness on every collision?
Help us help you: attach a .love.
- Taehl
- Dreaming in associative arrays
- Posts: 1025
- Joined: Mon Jan 11, 2010 5:07 am
- Location: CA, USA
- Contact:
Re: Weightless Physics object
Ah, I thought it was horizontal platforms that were causing you problems. Oh well.
Earliest Love2D supporter who can't Love anymore. Let me disable pixel shaders if I don't use them, dammit!
Lenovo Thinkpad X60 Tablet, built like a tank. But not fancy enough for Love2D 0.10.0+.
Lenovo Thinkpad X60 Tablet, built like a tank. But not fancy enough for Love2D 0.10.0+.
- tentus
- Inner party member
- Posts: 1060
- Joined: Sun Oct 31, 2010 7:56 pm
- Location: Appalachia
- Contact:
Re: Weightless Physics object
Ah! I have not used masks yet, I should acquaint myself. Let's see... you would use setCategory(x) on the invisible box, and then setMask(x) on the the platform, right? Given that both xes are the same number of course... and there are at most 16 possible categories, correct?Robin wrote:No, use shape:setMask().tentus wrote:Actually, how would you do a box that only collides with platforms? Toggle its sensorness on every collision?
I love getting answers I hadn't even considered, it keeps my brain active.
Kurosuke needs beta testers
Who is online
Users browsing this forum: Ahrefs [Bot], Google [Bot] and 225 guests