# Bezier Curves

I didn’t know where to ask this question - if it should be somewhere else, kindly move it, and sorry for the inconvenience in advance.

Hi guys, I’m reading about Bezier Curves. Why are they used in games? And just how much are they used in games, especially in Platform Games?

The reason I’m asking is that I am developing a prototype platform game and an accompanying custom physics engine, and for curves I was going to create a normal image (as a display), then associate that curve with a formula/function (for example y = (x2)/2 ) and use a formula to detect collisions.

PS To get a general idea, take ‘platforms’ to be like Sonic’s, or Element4l’s.

The “why” is because you can get a nice curved area with only needing a few points. You only need a start/end and some control points to define the curve between the 2 points. You can also do a lot of other useful math with them.

However for platformers most “curves” come from very simple emergent behaviour.

I.e. each frame accelerate downards for gravity and the result is a nice arc.

HeroDex has a lot of cards flying around in curves and it is virtually all done as emergent behaviour by applying forces.

ye for a physics engine, you are gonna want to look more into acceleration/velocity, forces/momentum, friction, moments, torque (mechanic equations). I.e a simple example:

If I throw a ball in the air that weighs 0.5kg from an initial velocity of 5m/s starting from 1m off the ground, what height will it reach a rest velocity (i.e v = 0) i.e when does it start coming crashing back to earth

I hope I gave enough variables to solve this ^^, actually dam, I’d better go consult my high school notes xD

The point is that you don’t solve it (unless you need really accurate physics results not game physics results but that’s a whole different kettle of fish). Just apply acceleration downwards each frame and you get a nice curve automatically.

For creating your own physics engine, you won’t be solving problems like that (well depends what your doing), but you still need to know the same fundamental equations used in solving them (so doing them helps :))

Edit:
Using the acceleration equation: v^2 = u^2 + 2as

I got a displacement of 0.458m, so a total height reached of 1.458m, can anyone else confirm? xD

@wezrule, I got 1.25m, a total of 2.25m

v = 0, therefore 0 = u^2 + 2as
u = 5, therefore -25 = 2as
a = -10, therefore 2.5 = 2s
therefore s = 1.25m.

That aside, I don’t think you got the point. Sorry if it was my fault. Let’s say I model part of the ‘terrain’ or a platform in the shape of y = (x^2)/2 between x = -4 and x = 0: http://www.wolframalpha.com/input/?i=y+%3D+(x^2)%2F2+between+-4+and+0 - or any shape really - look at this from Element4l:

Should I use a bezier for a platform, or should I ‘paint’ the sprite myself, then calculate collisions by a formula (which I already have)? What would be the best practice, especially to check collisions?

Also, thanks for your help so far

I think you would rarely need to solve the equation that way.

v = v + a * tpf;
p = p + v * tpf;

That’s physics.

You can draw curves from those or you can get nice parabolic trajectories for those. Sometimes AI will want to predict where something could go and there are derivations of that online all over the place. But for a simply physics engine it’s usually just ok to project ahead like the angry birds parabolas.

Edit: my response was meant to be before the last one.

@pspeed, please refer to my last post, since I initially explained myself awfully

<cite>@memonick said:</cite> @wezrule, I got 1.25m, a total of 2.25m :P

yh ur right, for some reason I put u = 3 >_<

@memonick said: @pspeed, please refer to my last post, since I initially explained myself awfully :/

Please see my edit that my post was in response to wezrule as we take this thread a bit off topic now.

I think you should use whatever curve equations that you can get accurate normals from… and where you can set sensible control points or whatever. If bezier curves work then why not use them. If they don’t then use 2D nurbs or something where the normals are easily derived.

I do like derailing threads For 2D bezier curves, you can get the normals of any point along it by finding the derivative (tangent vector), and then you can get the normal using that.

<cite>@pspeed said:</cite> v = v + a * tpf; p = p + v * tpf;

That’s physics.

Yep, they are all part of the same family of equations though (well your first one at least, in the form of v = u + a*t). You can derive that equation, from mine, and vice versa. Funnily enough out of the 5 of them, I chose a problem which doesn’t use time xD

Edit:

<cite>@memonick said:</cite>
Should I use a bezier for a platform, or should I ‘paint’ the sprite myself, then calculate collisions by a formula (which I already have)? What would be the best practice, especially to check collisions?

Also, thanks for your help so far

Well if you can mathematically describe something, then that gives you a lot of power. But any reason you cant make your life simpler and use a 2D physics engine?

Yes, wezrule, I’m talking about a Physics engine The thing is, I don’t know whether to go with bezier curves or the method I mentioned before to calculate collisions.

Well there’s loads of ways to achieve what u want. From the screenshot above, you can certainly use Bezier/splines/b-cuves/nurbs or w.e and join loads of them up with G1 continuity procedurally. You can even use parts of sine curves potentially. Once you’ve got them, build a mesh then if the balls bounding sphere is no longer within the bounds of the closest curves ( there will be many ways to check this). Then push the ball off in the normal direction or use it to reflective off, or w/e u choose, adjusting for loss of energy for the impact, based on friction of surface, impact velocity etc

Thanks, I think I’ll go with my way, since it doesn’t involve too many calculations and I’m sure it will work.

Just be aware of tunnelling effects if using discrete as opposed to continuous collision detection.

Tunneling effects as in collisions with ceilings and floors? I’ve got that covered too, since I’ll be using the forces’ components.

As in small objects passing through each other rather than colliding since they “jump” the distance in a frame.

Thanks for the heads-up I’ll be using continuous collision detection by checking whether two lines (one is the path, the other is the platform) intersect.