Hey guys. Im new to Love and started a programming in Love a couple days ago and I am just plain stuck when it comes to using the physics engine. Nothing works out as I would imagine.
So first off I want to know a couple good values for things such as mass for a character and values for gravity. Secondly, I am making a platform game which doesnt need to have platforms that allow you to jump up through or anything, I just need a character that reacts to physical objects doesnt go through walls or floors and falls at a normal rate. How do I go about doing stuff such as movement? Should I use applyForce() or applyImpulse()? So far in order to stop my character from rotating I just give him a circle shape and have the character draw without angle modifications. This lead to problems with the circle continuing to rotate cause the character to glide. I think I just had to jack up the angular damping to make the character come to a stop. Another problem I've had besides rather slow gravity for my character, is that when moving from side to side the character falls slower.
Overall I have just a ton of problems. I will attach a zipped .love file. I am using the ENVY framework and inside my /game/entities folder is a couple versions of my main character or player the only one that should be ignored is prop_player.lua... the rest are different techniques for trying to model the player. The methods used are the circle method mentioned above, two other methods like the circle method but with what is supposed to be a hexagon and octagon, trying to use a sensor shape instead and write my own physics for just the character but that died when I realized that the character is affect by gravity regardless of it being a sensor, and finally the prop_new_player.lua is the player with rotating ability using a rectangle for its shape... Help is appreciated in any form.
--peace
Le Jeune Renard
Physics are a pain.
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
-
- Prole
- Posts: 11
- Joined: Mon Apr 13, 2009 7:33 pm
- Contact:
Physics are a pain.
- Attachments
-
- Envy Us.zip
- (493.55 KiB) Downloaded 317 times
Re: Physics are a pain.
Good Gravity: 50 works best, I find. But it's not always a universal truth. It depends on your game.
Good Mass: Depends. The more mass you give something, the harder it is to move. If you give it no mass, it's an immovable object. But you have to specifically tell the physics engine that it's got no mass. Simply not assigning mass doesn't seem to work (for me anyway).
ApplyImpulse vs ApplyForce: Impulse is an immediate jolt NOW. Force is applied over time. Here's a demo I whipped up to demonstrate that:
Keys:
WASD : Apply IMPULSE
Arrows / Cursors : Apply FORCE
M: Give the object MASS
Z: Give the object ZERO MASS
R: Reset
Try the IMPULSE, first. Then try FORCE. Remember: You have to strike the key REPEATEDLY to get any results. If you follow, you can strike "W" to go back up a few times and you're already fighting gravity pretty handily. You have to strike "Up" again and again to even begin to fight. If you strike fast and strike often, you'll eventually fight gravity, but it's a pain to do so. If you hit "M", it doesn't matter WHAT you do: it's got too much mass for the impulses and forces we're directing upon it. If you hit "Z", the engine knows the object specifically doesn't have ANY mass and is therefore a fixed point and the object immediately stops moving.
As for the rest, you'll have to wait for someone else to happen along. My brain isn't firing on all cylinders, so I can only crap out information that I know like the back of my hand or that I can Google easily. I hope this was helpful. Anyone that knows better than me, feel free to set the record straight. I'm not guaranteeing this information in any way shape or form is the most accurate or the best method.
*EDIT* Whoops, had one of my keys doing the wrong thing with impulse. My bad!
Good Mass: Depends. The more mass you give something, the harder it is to move. If you give it no mass, it's an immovable object. But you have to specifically tell the physics engine that it's got no mass. Simply not assigning mass doesn't seem to work (for me anyway).
ApplyImpulse vs ApplyForce: Impulse is an immediate jolt NOW. Force is applied over time. Here's a demo I whipped up to demonstrate that:
Code: Select all
function load()
initVars()
end
function update(dt)
world:update(dt)
end
function draw()
love.graphics.circle(1, myShip:getX(), myShip:getY(), myShipShape:getRadius())
end
function keypressed(key)
--Apply Force
if key == love.key_up then
myShip:applyForce(0, -500)
elseif key == love.key_down then
myShip:applyForce(0, 500)
elseif key == love.key_left then
myShip:applyForce(-500, 0)
elseif key == love.key_right then
myShip:applyForce(500, 0)
end
if key == love.key_w then
myShip:applyImpulse(0, -50)
elseif key == love.key_s then
myShip:applyImpulse(0, 50)
elseif key == love.key_a then
myShip:applyImpulse(-50, 0)
elseif key == love.key_d then
myShip:applyImpulse(50, 0)
end
if key == love.key_m then
myShip:setMass(0,0,50,0)
end
if key == love.key_z then
myShip:setMass(0,0,0,0)
end
--Press "R" to reset the demo
if key == love.key_r then
initVars()
end
end
function initVars()
world = love.physics.newWorld(1000,1000)
world:setGravity(0, 50)
myShip = love.physics.newBody(world, 500, 50)
myShipShape = love.physics.newCircleShape(myShip, 16)
end
WASD : Apply IMPULSE
Arrows / Cursors : Apply FORCE
M: Give the object MASS
Z: Give the object ZERO MASS
R: Reset
Try the IMPULSE, first. Then try FORCE. Remember: You have to strike the key REPEATEDLY to get any results. If you follow, you can strike "W" to go back up a few times and you're already fighting gravity pretty handily. You have to strike "Up" again and again to even begin to fight. If you strike fast and strike often, you'll eventually fight gravity, but it's a pain to do so. If you hit "M", it doesn't matter WHAT you do: it's got too much mass for the impulses and forces we're directing upon it. If you hit "Z", the engine knows the object specifically doesn't have ANY mass and is therefore a fixed point and the object immediately stops moving.
As for the rest, you'll have to wait for someone else to happen along. My brain isn't firing on all cylinders, so I can only crap out information that I know like the back of my hand or that I can Google easily. I hope this was helpful. Anyone that knows better than me, feel free to set the record straight. I'm not guaranteeing this information in any way shape or form is the most accurate or the best method.
*EDIT* Whoops, had one of my keys doing the wrong thing with impulse. My bad!
We don't borrow, we don't read, we don't rent, we don't lease, we take the minds!
-
- Prole
- Posts: 11
- Joined: Mon Apr 13, 2009 7:33 pm
- Contact:
Re: Physics are a pain.
Ok, I changed your example a little so as to make the controls apply impulse and force constantly while the button is pressed. This is more what it would be like for a platform game for the side to side movement. When I do this one of my problems with the physics engine becomes apparent. As the object is falling, I apply a force horizontally (in other words there is no vertical component to the force I am adding). Immediately the object ceases to fall the same vertical speed. Instead it moves mostly in the horizontal direction. The engine must be replacing not applying the force to the object.
Any help understanding what I am doing wrong or what the limitations of the physics engine, would be appreciated.
Any help understanding what I am doing wrong or what the limitations of the physics engine, would be appreciated.
Re: Physics are a pain.
If you're using impulse, the reason this is happening is because you're basically shoving the object instead of causing it to gain momentum over time. I think if you look closely, you're actually falling at a constant speed, but you're going so quickly left or right that it's darn near impossible to tell, because the changes made going that direction are so monumental.
Other than that, I'd almost have to see the code to understand what you're trying to do.
Other than that, I'd almost have to see the code to understand what you're trying to do.
We don't borrow, we don't read, we don't rent, we don't lease, we take the minds!
Re: Physics are a pain.
The most important thing to remember when dealing with physics is that Box2D works best with objects in the size range of 0.1 to 10. Any values that fall outside of that risk being modeled very incorrectly. This means that you should (almost) never use pixel values to represent the size of things, at least on the physics side of things.
Also, it's worth noting that the impulse and force functions are currently broken. I've already sent in a (untested) patch, but who knows when it will actually get applied. I would upload it here, but apparently ".patch" is too sketchy a file extension. If anyone wants it, PM me.
In other words, lejeunerenard, it's not your fault.
Also, it's worth noting that the impulse and force functions are currently broken. I've already sent in a (untested) patch, but who knows when it will actually get applied. I would upload it here, but apparently ".patch" is too sketchy a file extension. If anyone wants it, PM me.
In other words, lejeunerenard, it's not your fault.
-
- Prole
- Posts: 11
- Joined: Mon Apr 13, 2009 7:33 pm
- Contact:
Re: Physics are a pain.
Thank you Alex. I sent you a PM about the patch how exactly to scale. I have also noticed that setVelocity() must be broken too because I tried that approach as well storing the old vertical component and changing only the horizontal component...
Xcmd: I did notice that it does continue to fall but at a much slower speed than it should. If you apply a horizontal force it should only change the acceleration horizontally. I have attached a version of your example with the ability to constantly apply force and impulse as well as displaying the current velocity of the object.
--peace
Le Jeune Renard
Xcmd: I did notice that it does continue to fall but at a much slower speed than it should. If you apply a horizontal force it should only change the acceleration horizontally. I have attached a version of your example with the ability to constantly apply force and impulse as well as displaying the current velocity of the object.
--peace
Le Jeune Renard
- Attachments
-
- Physics example.love
- (802 Bytes) Downloaded 354 times
Re: Physics are a pain.
I'm pretty certain Box2D is simulating air friction, which I think you're expecting not to be there:
(Incidentally, I think I may have just proven myself wrong in several other replies...)Box2D Manual section 6.2.1 wrote:http://www.box2d.org/manual.html#d0e815
Friction is used to make objects slide along each other realistically. Box2D supports static and dynamic friction, but uses the same parameter for both. Friction is simulated accurately in Box2D and the friction strength is proportional to the normal force (this is called Coulomb friction). The friction parameter is usually set between 0 and 1. A value of zero turns off friction and a value of one makes the friction strong. When the friction is computed between two shapes, Box2D must combine the friction parameters of the two shapes. This is done with the following formula:
float32 friction;
friction = sqrtf(shape1->friction * shape2->friction);
We don't borrow, we don't read, we don't rent, we don't lease, we take the minds!
Re: Physics are a pain.
To the best of my knowledge, Box2D does not model air friction. It does support linear damping, which I suppose acts sort of like air friction. Real air friction would probably be much to expensive to model properly. The section you quoted deals with friction between two solids.Xcmd wrote:I'm pretty certain Box2D is simulating air friction, which I think you're expecting not to be there:
Re: Physics are a pain.
I could be wrong. *shrug* But the way they phrase it, it seems like it's doing both. Although the very first sentence does pretty much say it's limited to body interactions.Alex wrote:To the best of my knowledge, Box2D does not model air friction. It does support linear damping, which I suppose acts sort of like air friction. Real air friction would probably be much to expensive to model properly. The section you quoted deals with friction between two solids.Xcmd wrote:I'm pretty certain Box2D is simulating air friction, which I think you're expecting not to be there:
We don't borrow, we don't read, we don't rent, we don't lease, we take the minds!
-
- Prole
- Posts: 11
- Joined: Mon Apr 13, 2009 7:33 pm
- Contact:
Integrating Envy with CAMERA
Hey so now Im trying to use CAMERA to scale everything and got most of it too work but Im finding problems with stuff such as text. I was wondering if there is a particularly good way to integrate CAMERA and Envy...
Who is online
Users browsing this forum: Bing [Bot] and 2 guests