Quarter Circle Path

G

Glengui

Guest
Hello GameMaker community,

I am making a grid-based game similar to Simcity or Transport Tycoon, where cars travel over roads tiles. Each of my road tiles has a pre-defined path, most are straight or left/right turns.

My problem is that I can not get the left/right turn paths to follow a perfect (or near-perfect) circular shape. They turn out more like cantilevered curves (sharper in the center, wider at sides). See the attached pictures.
Is there a way to define a more circular path?

Thank you for any help you can offer!

And yes, those goofy circle-arrow things are my artist rendition of a car ;)

overall.png

roadTL.png
 
T

Tyler Logsdon

Guest
Also it looks like you're using game maker 8 or 8.1 maybe time for an upgrade
 
G

Glengui

Guest
Hey guys, thank you for the reply. The path Simon Gust offered is not a perfect quarter circle, it also has a curved middle section, and two straight areas on either end.
Should I assume that a path consisting of purely the curved area is not possible? Reducing the x,y values did not eliminate the straight sections, it just scaled down the problem.
 
G

Glengui

Guest
I was able to make a close approximation. I guess that's acceptable. Is there really no way to correctly, or mathematically, make this any more precise?

roadTL_approx.png
 
L

Lysho

Guest
If you want a perfect quarter circle then you need to make all the points have the same radius from the center. So say your bottom left point is 3 units down, and your upper right point is 3 units right. Those are in sync with each other, they're both 3 units away from the center which is 0,0 in this case, so thats good so far. You want the other, middle point to be 3 units out diagonally from this center. It can be hard to eyeball, but simple geometry can give you the perfect answer. You basically want to know how far right and how far down to make the middle point, so you want a certain distance or length. This distance can be solved by imagining a 45/45/90 triangle, where the hypotenuse is equal to 3(the radius), and the legs are both equal to some answer A. See the terrible drawing I made in paint in 2 minutes that sort of shows what I'm trying to say.

<Image Link Removed - Malicious Domain Detected>/kTooqa
<Image Link Removed - Malicious Domain Detected>/kTooqa
Algebra reveals A to be 2.12, which means you need that point to be 2.12 units to the right and 2.12 units down from the center of the circle, aka you want the middle point to be at (2.12,2.12). Unfortunately, it doesn't seem that GM will let you put points on decimal units. You could get pretty close by using 2, though, in this example. If your tracks are bigger, you can probably get even closer. For example, if the radius is 400, then the A would be 282.8, which is really close to 283. It might even be close enough to appear perfect to the eye in-game.
 
G

Glengui

Guest
Thank you Lysho, geometry is no problem for me. In the above picture, I was roughing out the points using your method. More points give more accuracy, but eventually it just gets tedious.
Like you said, GM won't allow decimal units. Combine that with Simon Gust's post, which shows the path not actually going through each point. It looks like a close approximation is the best that can be done.
 
L

Lysho

Guest
Another solution might be to create the path in code instead of the path editor, which I believe could handle decimal points. Check out this page:

https://docs.yoyogames.com/source/dadiospice/002_reference/paths/changing paths/path_add_point.html

The example at the bottom details how to make circular paths. There are also more path functions so that you don't have to repeat it for every turn; just mirror and copy and add to existing paths. You could construct the whole path as one big path, adding on piece by piece, or construct path fragments like each quadrant of a circle and horizontal/vertical lines, and then add fragments together into a final path, tacking one copy of a fragment onto another. I recommend this solution because it opens up the possibly of changing the path much easier, adapting to new maps for example.
 
G

Glengui

Guest
Hey! That works pretty well. Thank you, Lysho. I had to modify the code you indicated, but the car/blobs follow a very smooth circular path now. (see the 2x2 tile in the lower right)

Hello math, goodbye human error. ( well... this ONE error ;) )

overall_round.png
 
Top