0
\$\begingroup\$

I have a path made using segments of sine wave interpolation put together that is drawn flat on the screen. And I would like to give the path the effect of coming towards the player. I tried to draw what I want to do, left is what I have now and right is the desired effect:

enter image description here

so the "farther" away the end of the segment is the smaller it's scale is and the segments are closer together. I think this would give the effect I'm looking for but I'm not sure how to do it.

This is the code I use to create a segment. It keeps track of the last point of the segment so the next segment can start from there.

private void createSegment() {
    int g = r.Next(i, i + 240);
    for (float j = 0; j < 1f; j += 0.01f) {
        Points.Add(new Vector2(CosineInterpolate(lastX, g, j), startY));
        startY--;
    }
    lastX = g;
}
\$\endgroup\$
  • \$\begingroup\$ Do you want draw a path that looks like this or do you need pseudo 3D in your game? In other words; will game characters move along the path? \$\endgroup\$ – Felsir Jan 19 '19 at 19:08
  • \$\begingroup\$ You can animate this by frames. Or use scale to change the size. \$\endgroup\$ – Omer Jan 19 '19 at 19:40
  • \$\begingroup\$ I did manage to scale the points accordingly like in the image I posted. The bigger problem for me is how to give the effect of the wave unraveling as it comes towards the bottom of the screen. I'm thinking maybe a shader with a bump map (I think that's what it's called)? But I barely have any experience with shaders but if you guys tell me it would work than I would work on that. Also nothing will be on the path so that's not an issue. \$\endgroup\$ – memelord420xd Jan 19 '19 at 19:49
  • \$\begingroup\$ A shader and bumpmap don't sound like the solution here. My question still remains- if you just want to draw a sine wave that becomes wider as you get closer to the bottom of the screen, simply scale it- if you want pseudo 3D, you need to approach it differently. \$\endgroup\$ – Felsir Jan 19 '19 at 22:13
  • \$\begingroup\$ In this case you can use "Sprite Mask" and make it show the path from far to near screen. \$\endgroup\$ – Omer Jan 20 '19 at 19:49
1
\$\begingroup\$

I will make some assumptions about your function, that you need to call it twice, once for both the left and and right hand sides of your road. For what you are doing, you are close.

private void createSegment(float desiredWidth, float direction, List<Vector2> pointsList) {
    int g = r.Next(i, i + 240);
    for (float j = 0; j < 1f; j += 0.01f) 
    {
        float modifier = desiredWidth * j * direction;
        pointsList.Add(new Vector2(CosineInterpolate(lastX, g, j), startY) + new Vector2(modifier, 0));
        startY--;
    }
    lastX = g;
}

I'm going to assume that you will have 2 lists that will represent the left and right hand sides. And that as you iterate through creating your list of points. Just a heads up, you can use any sort of scaling in the modifier variable. You may want to add some small exponential calculation if you want to make it look more 3d.

as mentioned, i've made some assumptions about what you're trying to achieve. If this isn't a fit, then all ok! GL

| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ Your assumptions are very correct and this is definitely very helpful! Thank you. \$\endgroup\$ – memelord420xd Jan 22 '19 at 22:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.