Results 1 to 5 of 5

Math Help - Computer game question Mk II

  1. #1
    Newbie
    Joined
    Mar 2009
    Posts
    8

    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.
    Last edited by quickieau; March 8th 2009 at 05:52 PM.
    Follow Math Help Forum on Facebook and Google+

  2. #2
    Newbie
    Joined
    Mar 2009
    Posts
    8

    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.
    Last edited by mr fantastic; March 11th 2009 at 05:53 AM. Reason: This is a Moderator approved bump.
    Follow Math Help Forum on Facebook and Google+

  3. #3
    MHF Contributor

    Joined
    Aug 2008
    From
    Paris, France
    Posts
    1,174
    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).
    Last edited by Laurent; March 12th 2009 at 07:36 AM.
    Follow Math Help Forum on Facebook and Google+

  4. #4
    Newbie
    Joined
    Mar 2009
    Posts
    8
    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.
    Follow Math Help Forum on Facebook and Google+

  5. #5
    Newbie
    Joined
    Mar 2009
    Posts
    8
    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
    Follow Math Help Forum on Facebook and Google+

Similar Math Help Forum Discussions

  1. Game Theory: Hotelling game with 3 players
    Posted in the Advanced Applied Math Forum
    Replies: 2
    Last Post: March 26th 2011, 03:08 AM
  2. Dot Game Theory Question
    Posted in the Advanced Math Topics Forum
    Replies: 4
    Last Post: October 31st 2009, 06:10 PM
  3. Question about a game
    Posted in the Advanced Statistics Forum
    Replies: 1
    Last Post: February 5th 2009, 08:12 AM
  4. Sequential-form game (game tree diagram)
    Posted in the Advanced Statistics Forum
    Replies: 0
    Last Post: October 5th 2008, 07:51 PM
  5. Card game question - Yaniv card game
    Posted in the Discrete Math Forum
    Replies: 1
    Last Post: August 3rd 2008, 01:36 AM

Search Tags


/mathhelpforum @mathhelpforum