mapeditor / tiled

Flexible level editor
https://www.mapeditor.org/
Other
10.87k stars 1.73k forks source link

Collision capsule #2153

Open justgook opened 5 years ago

justgook commented 5 years ago

For physics engine much easier is deal with capsules instead of ellipse, now on tiled side i use ellipse to determinate capsule colliders, would be nice to have ability, to switch between ellipse / capsule representation of circles when width and height are not equals, or maybe just add new shape ? CapsuleCollider2D-Example2

bjorn commented 5 years ago

Hmm, that'd definitely be an interesting new shape to add. Looks like it would not be a big change to support it. Which physics engine are you using?

justgook commented 5 years ago

im creating my own.. and that example came from Unity tutorial..

bjorn commented 5 years ago

So I guess this shape is not commonly supported by collision engines, but it could still be generally useful since it can be easily converted to two circles and a rectangle or a polygon if needed.

Would you like to have a go at adding this?

justgook commented 5 years ago

im not really good in C++ stuff.. so not really have clue how / where to add / make PR.. but that is kind of base shape for most of game engines, to represent characters.. and that also have lot of examples in 3d,

SSBMTonberry commented 5 years ago

For physics engines used in games, this is a actually a very common shape, and would be great to have in Tiled! It's commonly used for player objects or any other objects that does not fit a square shape. Square shapes and collisions tend to be a bit tricky to handle smoothly using physics engines, which is why circles and capsules are commonly used for moving objects.

bjorn commented 5 years ago

@SSBMTonberry Right, but at the same time I don't know about any (2D) physics engine that specifically supports capsules. Chipmunk2D has circles, lines and polygons. Box2D (and hence planck.js) do convex polygons and circles (lines as well), Matter.js supports polygons and circles. I haven't yet found a library that does capsules.

So, it appears to me that a capsule will generally need to be modeled with either a polygon or combination of a box and two circles. And in that case I don't see a big advantage of having a capsule directly supported in Tiled. But in any case I'm certainly not opposed to adding it.

Maybe I can help you getting started with the C++ part, @justgook. There's a wiki page about Contributing to Tiled that's meant to guide you through setting up your development environment.

bjorn commented 5 years ago

Erm, alright, you mentioned a Unity tutorial, but in fact your example comes from the Unity 2D physics engine, which apparently does support capsules. So we've found a pretty significant one. :-)

SSBMTonberry commented 5 years ago

@bjorn : Capsules are usually made by combining a box and two circles, like you say. I'm using a collision detection library called cute_c2, which is a single header library. It supports capsules directly. For both Box2D and Chipmunk I think the most common way of producing capsules is by combining two circles and a box, which a capsule is made of anyways.

Seanba commented 5 years ago

Small request if this is added to Tiled: Please point me to the parametric equation used to approximate the shape of these capsules. I will add that to SuperTiled2Unity. Thanks!

bjorn commented 5 years ago

@Seanba Hmm, what do you need that for? I'm not sure what such an equation would look like. Why not use two circles and a box to model the exact shape?

Seanba commented 5 years ago

@bjorn Under some conditions I have to approximate all shape types as polygons. I figured I would piggy back on whatever you use for displaying the outline of a capsule shape but I've got other ways to get what I need through the Clipper library if need be. :)

TheRealOrangus commented 4 years ago

In Chipmunk2D, segments have a "radius", essentially making them capsules.

jrasanen commented 1 year ago

Godot the game engine also uses capsules, as well as Rapier.

CurryOnRice commented 1 month ago

It would be nice to see capsules implemented for added Godot support!