Understanding Physics

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
Xcmd
Party member
Posts: 211
Joined: Fri Feb 13, 2009 10:45 pm

Understanding Physics

Post by Xcmd »

So right now I'm attempting to educate myself on the physics system. So far... weird! I've gotten a few things to work, here and there. Right now I'm trying to specifically educate myself on joints. I think I've figured out the RevoluteJoint (in as much as I can get one body to revolve around another body in a rag-doll fashion). Now I'm trying to get my head around DistanceJoint. Here's what I've come up with so far:

Code: Select all

-- Orbit

function load()
	world = love.physics.newWorld(1000, 1000)
	
	bodyA = love.physics.newBody(world, 500, 500)
	bodyB = love.physics.newBody(world, 100, 100)
	jointA = love.physics.newDistanceJoint(bodyA, bodyB, 0,0,50,50)
	jointA:setLength(100)
	
	shapeA = love.physics.newCircleShape(bodyA, 16)
	shapeB = love.physics.newCircleShape(bodyB, 16)
	
	bodyA:setSpin(36)
end

function update(dt)
	world:update(dt)
end

function draw()
	love.graphics.circle(1, bodyA:getX(), bodyA:getY(), shapeA:getRadius())
	love.graphics.circle(0, bodyB:getX(), bodyB:getY(), shapeB:getRadius())
end
The two orbit each-other beautifully, but I don't really understand how or why. Mostly I'm confused about the two points I set in the DistanceJoint itself. Are those coordinates World Origin or Body Origin? Because when I set them to 500,500,100,1000 then the two points immediately move right to each-other to the outer limit of the distance I set and then... they just stop. But if I set one of them to 0,0 then I get this weird orbital pattern. I'm going to continue playing around with this, but maybe someone can shed some light on this for me?
We don't borrow, we don't read, we don't rent, we don't lease, we take the minds!
User avatar
Xcmd
Party member
Posts: 211
Joined: Fri Feb 13, 2009 10:45 pm

Re: Understanding Physics

Post by Xcmd »

OKAY. So I think I get what's going on here:

MADNESS. So I give up on this and Prismatic Joints. I know Revolute Joints and I'm happy enough about that.
We don't borrow, we don't read, we don't rent, we don't lease, we take the minds!
Zett
Prole
Posts: 1
Joined: Sat Mar 21, 2009 6:42 pm

Re: Understanding Physics

Post by Zett »

RTFM :)

Meaning, you probably want to read http://box2d.org/manual.html and specifically for joint types take a look at http://box2d.org/manual.html#d0e984
User avatar
Xcmd
Party member
Posts: 211
Joined: Fri Feb 13, 2009 10:45 pm

Re: Understanding Physics

Post by Xcmd »

Actually I did read that, and it confused me more than anything else... *sigh* I should probably hang up the idea of using physics in my games. Oh well. ON TO THE NEXT THING!
We don't borrow, we don't read, we don't rent, we don't lease, we take the minds!
User avatar
Tenoch
Citizen
Posts: 76
Joined: Mon Jul 21, 2008 7:49 am

Re: Understanding Physics

Post by Tenoch »

Well, don't be too hard with yourself. In this case, the joints implementation is actually broken. So it's quite normal that you couldn't figure it out.
"When in doubt, use brute force." Ken Thompson
User avatar
Xcmd
Party member
Posts: 211
Joined: Fri Feb 13, 2009 10:45 pm

Re: Understanding Physics

Post by Xcmd »

I've still pretty much abandoned physics in my games for now... Of course I haven't been making a lot of games, lately. Mostly due to having the general buzz that is my brain not putting out anything of any use.
We don't borrow, we don't read, we don't rent, we don't lease, we take the minds!
Post Reply

Who is online

Users browsing this forum: _JM_, Google [Bot] and 38 guests