# Thread:

1. ## Computer game question Mk II

EDIT: I'm editing this post as even though it's notched up a few views no-one has yet replied. If I could just ask whether it's because I've posted this in the wrong forum, whether the problem is too hard, whether I haven't described the problem very well or if this kind of problem isn't the kind of thing that should be asked in these forums? Any response is much appreciated.

Hi,

I'm looking for some help for a computer game I am trying to write and not having done much in the way of complex math (when I say complex I mean anything more complicated than checking my credit card statement) for about 15 years my math is a little rusty - seems trial and error isn't a good way to go when trying to solve math problems! Anyway my frustration and ineptitude have got the better of me and I came across this forum in my search for help.

The easiest way to describe what I'm doing (or trying to do) is to have objects travel from the top of the screen to the bottom in the same way that the notes in Guitar Hero do. i.e. They not only travel down, but also out from the center to give the effect of perspective.

The screen has the dimensions of 800 pixels across by 450 down with the objects traveling down a "road" (or fretboard for Guitar Hero aficionados) that is placed in the horizontal center of the screen. The road is 200 pixels wide at the top widening to 800 at the bottom. While the horizontal center of the road is located at 400 pixels I have decided to refer to it as 0 (x position = x position - 400) since any object placed to the left of this point falls down and to the left, anything placed to the right of this point falls down and to the right, and any object placed directly at the center (0) will fall straight down.

The initial position of the objects are y:1 and x:random number between -100 and 100. I have the objects falling down in a straight line by calculating the next y position using NEXTy = OLDy * 1.2 This makes the object fall faster as it gets closer to the bottom, which is what I want so as to give the effect of getting closer.

What I need help in is creating a formula that calculates the NEXTx position as well. I'm guessing it will involve using the initial x position somewhere as it is this value (how far it is from the center) that will determine how sharp the angle the object will fall at and also the y position somewhere as well.

I hope I've explained my problem ok. Here's a few examples just to help clarify:
An object placed at (x,y) (50, 1) will fall in a straight line to (200, 450).
An object placed at (x,y) (-50, 1) will fall in a straight line to (-200, 450).
An object placed at (x,y) (100, 1) will fall in a straight line to (400, 450).
An object placed at (x,y) (-100, 1) will fall in a straight line to (-400, 450).
An object placed at (x,y) (0, 1) will fall in a straight line to (0, 450).

So the information I have is:
Initial x position of the object.
Initial y position of the object.
Next y position of the object.

And what I need is a formula that calculates the Next x position of the object.

Any help would be MUCH appreciated.

I know I've rambled on a lot compared to other problems on this site but I just wanted to make sure I was being clear and I'm not sure how to get my problem across in mathematical terms - I hope you'll forgive me. I also hope I've posted this in the correct forum. If not, let me know.

Thanks.

PS. If it makes it easier I can shorten the height of the playing area from 450 to 400 pixels.

2. ## Computer game question Mk II

Hi,

I'm rephrasing my original post in the hopes it generates more replies than my original long-winded description. Ok, here goes my attempt at brevity.

Consider a symmetrical trapezoid with a top side measuring 200, bottom side measuring 800 and height of 450.
Placing this trapezoid on a grid with the top left being considered (0,0) and the bottom right being (800, 450) will give the horizontal center of the trapezoid at x:400.

Assuming the initial x value is a random number between with a range 300-400 and the initial y value is 1 I need a formula that can give the x value on a graph based on an increasing y value and the original x value. (Man, this is hard to explain succinctly.)
The initial x value also needs to influence the calculation as it is this number that directly affects the result. The angle should also increase as the value of the initial x moves away from x:400 (the horizontal center).
eg. When the initial xy = 400,1 then x should remain 400 as y increases (as 400 is the center and effectively 0 for my purposes. But as the initial x increases to a maximum of 500 then when y = 450 then x should equal 800. When initial x = 450 then when y = 450 x should equal 200.

Hope that makes sense. If not read my essay above.
Thanks.

3. I had a look at a video from Guitar Hero on YouTube, and you explanation became crystal-clear! (or so I hope. You'll be able to judge from the following...)

The right side of the trapezoid, if extended, crosses x=0 when y=-150 (this can be proved with Thales' theorem, but a sketch would do fine).

Then the equations of the trajectories are $x=\lambda(y+150)$ for some $\lambda$ to be determined (this is the equation of a line, and when y=-150 this gives x=0).

It remains to find $\lambda$. We have the initial situation: when $y=1$, then $x=x_0$ (the initial position), which means $x_0=\lambda\cdot 151$, hence $\lambda=\frac{x_0}{151}$.

As a conclusion, the equation of the trajectory starting at $(x=x_0,y=1)$ is given by $x=\frac{x_0}{151}(y+150)$.

I think this is what you need.

Edit: actually there is little problem coming from the fact that we start at y=1 and not at y=0; the equation won't give you exactly what you want at y=450 for x=0, 50 and 100, and it can't. In the same way, I think x should actually go from 0 to 199; given that the screen width is even, there is not 1 pixel at the middle, but 2, so are there two initial positions that give vertical lines? Anyway, nobody will look very close at the screen to count pixels, so you can use the previous formula.

If you want to adapt your formula to another situation, here's a useful equation to remember: the equation of the line that goes through $(x_1,y_1)$ and $(x_2,y_2)$ is $x=x_1+\frac{x_2-x_1}{y_2-y_1}(y-y_1)$.

4. Hi,

Firstly Laurent I'd like to thank you for taking the time to try and decipher my post and respond - it puts you in a very select group! It also sounds like you've nailed my problem. With my limited math skills it might take a me some time to figure out your response which I hope to do tonight. Will let you know how I go.

BTW the only reason I used 1 for the initial y position is so I could apply a formula to work out the subsequent y positions and using 0 would just return 0 for next y = current y * 1.2 and thus wouldn't move from the y = 0. I think your suggestion to use 0 for the purposes of the x position formula would be fine since the objects won't actually be placed at y=0 as it won't be noticeable to the eye on screen.

Thanks again!! Stay tuned for good news (hopefully).

Darren.

5. Hi,

Good news. Your formula did the trick!! Can't thank you enough. I really appreciate it.

Now if I can only get the rest of program working.

Darren
{"extraction_info": {"found_math": true, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 0, "mathjax_display_tex": 0, "mathjax_asciimath": 0, "img_math": 0, "codecogs_latex": 12, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0}, "config": {"markdown_headings": true, "markdown_code": true, "boilerplate_config": {"ratio_threshold": 0.18, "absolute_threshold": 10, "end_threshold": 15, "enable": true}, "remove_buttons": true, "remove_image_figures": true, "remove_link_clusters": true, "table_config": {"min_rows": 2, "min_cols": 3, "format": "plain"}, "remove_chinese": true, "remove_edit_buttons": true, "extract_latex": true}, "english_confidence": 0.9496666789054871, "perplexity_flag": "middle"}