Physics Help, Please

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
i_love_u
Prole
Posts: 28
Joined: Sat Nov 29, 2014 12:13 am

Physics Help, Please

Post by i_love_u »

I use applyForce or applyLinearForce to push back an enemy when I attack them. Although, the problem is that if I attack him he seems as if he doesn't have any friction applied to the ground. He goes sliding off into the opposite direction. This also happens if I hit them midair, they go flying off!

Code: Select all

ai.body:applyForce(25000,-25000)
In real life, this doesn't happen. If you push a guy, he doesn't go sliding across town. What factors can you suggest need tweaking in order to correct this? Any help would be greatly appreciated! :awesome: :crazy: :huh: :cool: :o: :3 :death: :ehem: :emo: :halloween: :megagrin: :monocle: :brows: :neko:
User avatar
ivan
Party member
Posts: 1911
Joined: Fri Mar 07, 2008 1:39 pm
Contact:

Re: Physics Help, Please

Post by ivan »

Force (F) is measured in Newtons and related to acceleration:
F = m*a
m = mass
a = acceleration (change in velocity over time)

"applyForce" is generally used over time,
For example if you call "applyForce" for 10 seconds in a particular direction, you will get a "thrust" effect.

I think you are looking for "applyImpulse".
Impulse (J) is related to change in velocity (not acceleration!):
J = m*Vdt
m = mass
Vdt = change in velocity

So you want your enemies to fly off when you hit them, you would call "applyImpulse" only once where "Vdt" would the change in velocity.
For example, if you want the enemy to fly off at 10 meters per second, just multiply 10 by the enemy's mass.
IndieRetro
Citizen
Posts: 51
Joined: Mon Apr 15, 2013 8:21 pm
Contact:

Re: Physics Help, Please

Post by IndieRetro »

If this is a top down game, then do something like this:

Code: Select all

-- set the 'linear' damping
playerObjectBody:setLinearDamping(1)
https://www.love2d.org/wiki/Body:setLinearDamping

If it is a platform game, you generally want to set the friction of both the ground objects, and the objects standing on them.

Code: Select all

-- we apply friction to the fixture of the object
floorObjectFixture:setFriction(1)
playerObjectFixture:setFriction(1)
https://www.love2d.org/wiki/Fixture:setFriction

Hope this helps.
irc.freenode.org ##oodnet
http://exez.in/
Post Reply

Who is online

Users browsing this forum: No registered users and 27 guests