I am actually working on a little game. I am actually working with Love 0.8.0, but my question it not really specific to this version.
In some part of my game, I need to simulate physics. Please, don't tell me to use love.physics. I just want to make it on my own.
I wrote a custom vector class with deals with common operations (adding, substracting, multiplying, dividing vectors, dot product, etc...) and it works fine.
I also wrote a Object class, which represents objects moving under physics laws. I didn't wanted to call that Body or Rigid body, cause they just don't have all the real properties of Bodies. My Objects class just implements some basics methods (getters and setters for position, velocity, acceleration) and the main method for integration (Object:integrate)
Here is the code :
Code: Select all
function Object:integrate(world)
local resultingAcceleration = (self:getAcceleration()+ world.gravity)
local resultingVelocity = (acceleration*world.dt) + (self:getVelocity())
resultingVelocity = resultingVelocity - world.damping
self:setVelocity(resultingVelocity)
self:setPosition(self:getPosition() + (resultingVelocity*world.dt))
end
To resolve integration, each delta-time, we compute the new acceleration, taking account the gravity. The we update velocity, taking into account the damping, then we get the position.
Well, what do you think of it ? Am I doing something wrong ?
Fact is, in my game, objects are motionless at first, then they are being given a strong impulse and they moves in a 2D plane until they stop naturally.
Now, my point is...If i want to run this with löve (any version), how can i choose values/define units to have a nice simulation ? If i want the world gravity have the real gravity value (meaning vector(0, -9.81)), how can I use dt in love.update callback to have something which doesn't moves extremely fast... which moves really lövely ?
I hope ou get what I want to mean; sorry if my english sucks...