Hey everyone,
In my world I want some objects to fall, but other objects to rise up. I've tried using negative mass on some objects, but they dont move at all if their mass is negative unfortunately. Another option would be to create two worlds, one with gravity set in the opposite direction to the other. But if i do this then the objects from different worlds won't collide will they? How can this be achieved?
Make an object float up, like a balloon
- Robin
- The Omniscient
- Posts: 6506
- Joined: Fri Feb 20, 2009 4:29 pm
- Location: The Netherlands
- Contact:
Re: Make an object float up, like a balloon
The first thing that comes to mind (although probably a stupid idea) is to set the gravity of the "balloon" to zero, and all the things (including the view) go down. Not sure if it will work, though.
Help us help you: attach a .love.
Re: Make an object float up, like a balloon
That would be tricky, because i'd have to move any stationary platforms down with the view too.
I'm begining to think I might need to have zero gravity and accelerate the objects myself, some up, some down.
Does anyone know some love code for a psudo gravity function?
I'm begining to think I might need to have zero gravity and accelerate the objects myself, some up, some down.
Does anyone know some love code for a psudo gravity function?
- Robin
- The Omniscient
- Posts: 6506
- Joined: Fri Feb 20, 2009 4:29 pm
- Location: The Netherlands
- Contact:
Re: Make an object float up, like a balloon
Just apply some force? (I'm not that familiar with love.physics. I usually write my own simple physics from scratch )
EDIT: maybe this?
EDIT: maybe this?
Help us help you: attach a .love.
Re: Make an object float up, like a balloon
Cheers robin,
this is what i've come up with. works good enough for me:
Inside the update function.
this is what i've come up with. works good enough for me:
Code: Select all
for i = 1, #bodies do
local x, y = bodies[i].body:getVelocity()
if bodies[i].fall then
bodies[i].body:setVelocity(x, y+10)
else
bodies[i].body:setVelocity(x, y-10)
end
end
- Robin
- The Omniscient
- Posts: 6506
- Joined: Fri Feb 20, 2009 4:29 pm
- Location: The Netherlands
- Contact:
Re: Make an object float up, like a balloon
If it works for you, that's fine. But if you want collisions and such, setting static velocities won't do. If you apply a force once, at the beginning (the loading of a level, for instance), you don't have to set the velocity every update. (And, after all, gravity is just another force )
EDIT: I played with physics for a while, and it seems that even with applyForce, you have to apply it every update. However, that would be still better than setVelocity, because gravity accelerates objects, and setVelocity is awkward with collisions and such.
EDIT: I played with physics for a while, and it seems that even with applyForce, you have to apply it every update. However, that would be still better than setVelocity, because gravity accelerates objects, and setVelocity is awkward with collisions and such.
Help us help you: attach a .love.
Re: Make an object float up, like a balloon
But gravity is an continuous and accumulative force, so things that are falling accelerate. So I need the velocity to increase continuously, thats why i'm adding or subtracting 10 to the y velocity each frame depending on weather it's a riser or a faller. Giving the force just once on load wont have this result.
I'm not simulating a terminal velocity, but i dont think i need it in my game, as things fall/rise off the screen within a second or two.
I'm not simulating a terminal velocity, but i dont think i need it in my game, as things fall/rise off the screen within a second or two.
Re: Make an object float up, like a balloon
Collisions seem fine so far with the way i'm using setVelocity. But i'll bear what you say in mind incase i come accross any issues. Thanks.
Who is online
Users browsing this forum: Google [Bot] and 36 guests