Love2d physic for player-designed spaceships

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
User avatar
Luke100000
Party member
Posts: 232
Joined: Mon Jul 22, 2013 9:17 am
Location: Austria
Contact:

Love2d physic for player-designed spaceships

Post by Luke100000 »

Hello everybody! I'm planning a game where you can build your own spaceship out of iron-cubes (ship body, thrusters and so on). Your ship can collide with other objects (other ships, asteroids, ...) so I want to use the love physic engine.

My question: how I can use this engine that the correct cubes of the ship can be destroyed when crashing in another object? This should be very fast.

Here is an example like I want it:
http://gamedevelopment.tutsplus.com/tut ... medev-2610
User avatar
Luke100000
Party member
Posts: 232
Joined: Mon Jul 22, 2013 9:17 am
Location: Austria
Contact:

Re: Love2d physic for player-designed spaceships

Post by Luke100000 »

It's also OK if you can show me another physic-engine in Lua.
User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

Re: Love2d physic for player-designed spaceships

Post by kikito »

It's not the simplest game idea to implement. If this is the first game you have ever programmed, you might be eating more than you can chew. I am not trying to insult you, this is fairly common. If you haven't, I recommend you to do something easier first (like a regular shooter, with no ship parts).
how I can use this engine that the correct cubes of the ship can be destroyed when crashing in another object? This should be very fast.
If I were to do this, I would go with [wiki]love.physics[/wiki]. It's very well-suited for this kind of project, since the physics are more realistic than, say, a platformer.

My make-it-work-quickly implementation would be: Each ship part is a a [wiki]Body[/wiki] with a single square-shaped [wiki]Fixture[/wiki], connected to the rest of the ship parts via [wiki]WeldJoint[/wiki]s. Parts of the same ship don't collide with each other, unless they are "separated" from the core. Depending on whether this is fast enough or not, I would consider optimizations later on; I would certainly not attempt something more complex than that on the first go.

Good luck!
When I write def I mean function.
User avatar
Luke100000
Party member
Posts: 232
Joined: Mon Jul 22, 2013 9:17 am
Location: Austria
Contact:

Re: Love2d physic for player-designed spaceships

Post by Luke100000 »

It's not the simplest game idea to implement. If this is the first game you have ever programmed, you might be eating more than you can chew. I am not trying to insult you, this is fairly common. If you haven't, I recommend you to do something easier first (like a regular shooter, with no ship parts).

how I can use this engine that the correct cubes of the ship can be destroyed when crashing in another object? This should be very fast.



If I were to do this, I would go with love.physics. It's very well-suited for this kind of project, since the physics are more realistic than, say, a platformer.

My make-it-work-quickly implementation would be: Each ship part is a a Body with a single square-shaped Fixture, connected to the rest of the ship parts via WeldJoints. Parts of the same ship don't collide with each other, unless they are "separated" from the core. Depending on whether this is fast enough or not, I would consider optimizations later on; I would certainly not attempt something more complex than that on the first go.

Good luck!
No it's not my first game. :awesome:

I will damage ship parts with the CollisionCallback beginContact(a, b, coll).
How can I get the power of crashing?

Should I simulate thrusters with Body:applyForce ?

Thanks for helping me.
User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

Re: Love2d physic for player-designed spaceships

Post by kikito »

Luke100000 wrote:No it's not my first game.
I realize now that it seems I implied that; that's not what I meant. I meant the first game using love.physics. Sorry about the confusion.

Before doing a complex game with love.physics, you might want to start doing a shooter with ships made of solid bodies first - get them flying around, colliding etc. Then attempt the "ships-made-of-parts" approach.
Luke100000 wrote: I will damage ship parts with the CollisionCallback beginContact(a, b, coll).
How can I get the power of crashing?
If you are asking "how do I make one ship part collide with another one", that's also done with CollisionsCallbacks. To box2d, it doesn't matter if one thing is a bullet or not (*). By default it collides everything with everything. In fact what usually happens is that you have to manually trim down what collides with what.

(*) There is a difference, in that bullets tend to move much faster than regular objects, and their collisions have to be calculated differently. Some versions of box2d have a `setBullet` method to take this into account.
Luke100000 wrote:Should I simulate thrusters with Body:applyForce ?
Yes. But remember to make that force proportional to dt.
When I write def I mean function.
User avatar
Luke100000
Party member
Posts: 232
Joined: Mon Jul 22, 2013 9:17 am
Location: Austria
Contact:

Re: Love2d physic for player-designed spaceships

Post by Luke100000 »

If you are asking "how do I make one ship part collide with another one", that's also done with CollisionsCallbacks.
The faster the more damage the ship part will get by colliding, how can I get this damage? I only get "colliding" or "not colliding".
User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

Re: Love2d physic for player-designed spaceships

Post by kikito »

Well, before we hade [wiki]Contact:getVelocity[/wiki]. Now it's gone (why? I don't know).

I guess you can still get the relative velocity of the two colliding bodies by substracting their individual velocities:

Code: Select all

function getRelativeVelocity(a,b)
  local vax, vay = a:getLinearVelocity()
  local vbx, vby = b:getLinearVelocity()
  return vbx - vax, vby - vay
end
But I don't know, I haven't used love.physics since 0.8.x. Maybe there is a new way to do this.
When I write def I mean function.
Post Reply

Who is online

Users browsing this forum: No registered users and 14 guests