Love2d and radial gravity
Asked Answered
D

1

6

I've found an interesting article on adding radial gravity to box2d.

http://www.vellios.com/2010/06/06/box2d-and-radial-gravity-code/

To port this to lua though I need to calculate distance squared and normalize distance.

Love2d doesn't seem to have the functions to extract the appropriate vector, which is a shame.

Unless my math is lacking and somebody could help me out.

I can alway switch to box2d but love2d seemed like a neat solution.

Downfall answered 25/1, 2011 at 9:25 Comment(0)
D
5

I've found how to do it using the HUMP library.

Like this.

ship = bodies[1]
shipVec = vector(ship:getX(),ship:getY())
planet = bodies[2]
planetVec = vector(planet:getX(),planet:getY())
distance = planetVec – shipVec
force = 250 / distance:len2()
normforce = force*distance
bodies[1]:applyImpulse(normforce.x, normforce.y,ship:getX(),ship:getY())
Downfall answered 26/1, 2011 at 17:56 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.