Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Curved slopes #52

Open
colinvella opened this issue Oct 17, 2017 · 4 comments
Open

Curved slopes #52

colinvella opened this issue Oct 17, 2017 · 4 comments
Labels
Milestone

Comments

@colinvella
Copy link

colinvella commented Oct 17, 2017

I'd like to suggest the introduction of additional curved slopes like the ones below:

image

I understand that collision bodies for the sloped tiles are generated from polygons which are made of straight edges, but I think with some interpolation, curved slopes can also be generated programmatically.

The formula for the curved part of the 4 tiles above are:

  1. y = w - c(x)
  2. y = w - c(x + w)
  3. y = c(2w - x)
  4. y = c(w-x)

where c(x) = x^2 / 4w
and w is the width of the tile (e.g. 16, 32, 64, 128 etc.)
Note: I'm assuming that the Y axis points downwards, as per normal display convention.

When generating the curved slope, x would be sweeped from 0 to w by a step of 1 and y would be computed accordingly. For practical purposes, x can be incremented by a larger step, e.g. by w / 4 to reduce the number of sides.

An additional point for tile 1 and 4, or two points for 2 and 3, would need to be generated for the lower corner(s).

I can give you the formulas for the 4 tiles going down right, but as you might imagine, they are simple variants of tiles 1 to 4.

Notice how 2 and 3 have 45 degree slopes at one end, which makes it possible to combine them with straight 45 degree slopes.

Flatter versions (1/2 height) can be generated for transitioning on to straight 22.5 degree slopes as well, since their edge would end at halfway up the second tile with a tangent corresponding to the 22.5 slopes, so the second 22.5 straight slope can be placed next to it for a smooth transition.

These could be also extended to curved ceiling tiles, but they're not really that useful.

I could try extending your library myself, but I'm not sure I understand the rest of your code!

What are your thoughts on this?

@colinvella
Copy link
Author

Now that I think about it, tiles 1 and 2 are concave and hence not amenable to collision detection by SAT. Also, tiles 3 and 4, albeit convex, consist of many segmented sides constituting the curve, which would give the SAT solver a lot more to do.

@hexus
Copy link
Owner

hexus commented Oct 18, 2017

Yes, this wouldn't use proper SAT, but there is a solution for it.

http://www.metanetsoftware.com/technique/tutorialA.html#section2

See the "round shapes" subheading.

I didn't dive into this for the plugin because I didn't feel I was ready to at the time.

Hopefully this is something I could look into in the future, because then this would be the complete alternative solution to the deprecated Ninja Physics system.

@hexus hexus added the feature label Oct 18, 2017
@hexus hexus added this to the 1.0.0 milestone Oct 18, 2017
@hexus hexus changed the title Suggestion: Curved slopes Curved slopes Oct 18, 2017
@colinvella
Copy link
Author

The method described in that tutorial is quite interesting. I was surprised how it worked with the convex curve as well. It seems to be a hybrid that applies SAT on the horizontal and vertical axes but computes a an overlap projection along the normal to the curve in a different way.

Perhaps it's because a circular arc has certain properties. I don't know if the same assumptions can be applied to a polynomial curve as in my tiles above.

Anyhow, keep up the good work! This is really a great plugin!

@hexus
Copy link
Owner

hexus commented Oct 18, 2017

Thank you! I look forward to getting more time for it next year.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants