Page 1 of 2 1 2 LastLast
Results 1 to 10 of 12

Thread: wraparound equations for a top down shooter - all directions

  1. #1

    wraparound equations for a top down shooter - all directions

    Probably not the most descriptive header ever. Anyway.

    The game I'm picturing is a top down shooter, camera always centered on the Player Character, facing the mouse, with the terrain a random scattering of rocks and outcrops and such. I am having a problem with the wraparound functionality/maths however - basically the game is on the inside of a sphere, so walking in any direction will always bring you back to the same point. I've got no idea how to program this, though.

    Here's what I have so far;

    Start of frame - set Player X/Y Values to 500

    This is basically initialising Player position, telling everything from here on out that the character's starting pos is 500,500 in the virtual world, even though the technical frame coords are like 240/320 whatever.

    Start of Frame - Run loops to create Rock actives, includes set Rock XY values to (relevant maths to give them coords based on XY of Player)

    So again, rock coords are not based on their frame position, but the relative position compared to the player.

    The basic idea is when the Player "moves" (via a right click), as opposed to the Player moving in the frame, all the actives will shift around the Player based on the difference in desired position Coords vs current Coords. So if a right click points to a location that is, say, -20, -10 from the Player, all the items will shift -20, -10.

    Here's my issue. Trying to run this as a loop (if Mouse coord X different, +/- X coord of Rock objects etc) has an issue with Coord maths. In the above example, the movement will appear directly diagonal until the Y coord is matched (since it's changing both X and Y by 1 each loop), but since the X coord is still out by 10, it will then move in a straight line until it resolves back to 0/0.

    How can I get around this, and have the Player appear to move in a straight(ish - doesn't have to be perfectly 360) line to the desired click location? Any ideas will help.

    Thanks team!

  2. #2
    Clicker iOS Export ModuleInstall Creator Pro
    Dex's Avatar
    Join Date
    Jun 2015
    West Yorkshire, England
    Erm.... I THINK I understand what your wanting, but your making life complex for yourself mate.

    There is two ways to do this....

    1. Create a LARGE playarea...Then stick your player in the middle of it and tell the program that its to centre on the character.
    (If its a top-down game, then add rotations to your character.)
    Then just put the rocks, etc etc all over the screen.
    Because your only going to be showing a small section of the large screen at any time, when you move the screen scrolls in to view.

    However the better way to do it is this....

    2. Create a normal size playarea (say 1280 by 800??) ...Then stick your player in the middle of it.

    Then put the rocks all over the screen and OUTSIDE the screen area.

    When you move the player you DONT move him but instead you move the rocks in the other direction to what your wanting the players character to move in.
    So if you move right.... everything moves left. You get the picture?!

    All you then have to do is to tell the program that when a rock reaches a certain position, its to be placed back at its starting co/ords (in other words its like it just wraps around).

    And your done.

  3. #3
    Actually, a self-wrapping world is toroidal, and cannot be mapped to a sphere.

    I have been investigating this myself, since I'd like to create a defender-style and/or oids/thrust type game in which all game elements wrap the game world's four edges smoothly.

    The problem is two-fold: rendering of wrapped objects, and collision detection. In your case you would have to render and check for objects four times when the viewport straddles both x and y edges:


    The problem is that things like built-in physics may not work as expected. And during my research one developer who was busy implementing a self-wrapping game world warned anyone tackling this to think twice, because it will affect everything in your game, and introduce all sorts of possible bugs which you must solve.

    I still intend to look into this further, but so far no game engine seems to support this out-of-the-box.

    Has anyone here ever built a self-wrapping world for an action game in Fusion? Like the OP, I am also interested in implementing this for a game I have in mind. Similar to Gravitron 2:

    I happen to have the source code for Gravitron 2, but haven't found the time to check how that developer solved it (and being C++ based, it's quite opaque to check - so I've been putting it off).

    PS Gravitron 2 demo can be downloaded here:
    This is a cylindrical world that self-wraps horizontally. I would very much like to see if this could be achieved in Fusion.
    Images attachées Images attachées
    Last edited by Rayek; 16th February 2017 at 06:16 PM.

  4. #4
    @dex - Option 2 is basically what I already have. My problem is, when trying to use the mouse to control movement (picture any RTS style movement, but with the camera locked onto the unit you are moving) it will result in a perfectly diagonal line, followed by a straight line. Unless there's a super-duper equation out there to take the relative x/y differences and then only shift one x for every 3 y coords or something similar...

    Think it through and you'll discover my problem. As soon as I'm trying to shift all the terrain around the player, x and y coords will change at the same rate, if it's built with a basic loop of IF 'desired coordinates' are =/= current coordinates, then reduce terrain x/y by 1 or whatever. It seems simple, but it is not. As per the next post...

    @Rayek - I'm sure there's a way to achieve this. It might just take a few iterations of a beta world. You are very right in that things happening on the boundaries could get, to put it lightly, complicated. But thankfully the game I have in mind is not too heavy on physics or non-stop action, it's just easier to put a picture in other people's head by labelling it a top down shooter. Having a world bigger than the frame also helps to make things happen off camera.

    But anyway, it all comes down to adjusting the environment relative to the player, and doing so in a manner that is smoother than the jagged and awful diagonal then straight method that would result from the 'basic' coding of this. I think there's a bit of maths somewhere that can take the relative x and y distances the terrain needs to move, and ratio it up so that it looks nice and smooth. Something like if X change is more than double Y change, run loop x every second iteration of loop y blah blah blah. Makes sense in my head, not as easy to explain beyond that though.

    I think the great irony here is that in a 3d environment, this issue completely disappears and having my world inside a sphere is just... there. Who knew 2d could be so mathematically taxing.

  5. #5
    Disregard outmoded Dropbox references... *ahem*
    Last edited by 4burner; 17th February 2017 at 02:06 PM. Reason: I'm a fool

  6. #6
    Annnnnnd I just realised I could upload files directly to the website. Ignore the previous post *cough*
    Attached files Attached files

  7. #7
    Clicker iOS Export ModuleInstall Creator Pro
    Dex's Avatar
    Join Date
    Jun 2015
    West Yorkshire, England
    Ok 4Burner....Heres a routine I am using for a game im making..... please fell free to incorporate it in to yours if it helps.
    Last edited by Dex; 18th February 2017 at 12:44 PM.

  8. #8
    Nice example Dex. Might see if I can indeed utilise your work.

    I have an updated example of the wraparound. Now featuring 32 direction movement, eliminated the diagonal bug, and I gotta say it's pretty cool to see it functioning. It's a little jagged, obviously, but hopefully some work can eliminate that.

    BUT; if the express purpose of the project was to create a wraparound field with (near enough) freedom of movement from a top-down POV, then that has been achieved. Let me know what you guys think. Second frame is the updated version.
    Attached files Attached files

  9. #9
    I believe I figured out how Gravitron 2's horizontal self-wrapping works: the game's world is mapped to a 2d texture in opengl and texture wrapping is turned on.

  10. #10
    Clicker Fusion 2.5 DeveloperAndroid Export ModuleHTML5 Export ModuleiOS Export ModuleUniversal Windows Platform Export ModuleSWF Export Module
    aenever's Avatar
    Join Date
    Jun 2013
    4burner if you change lines 8 to 11 with repeat while joystick moved right, left down and top it will be as smooth as the original and 8 directions.

    Wraparound 8dir smooth.mfa

Page 1 of 2 1 2 LastLast

Similar Threads

  1. I need help making 8 Directions platform shooter
    By 4MindsStudio in forum Fusion 2.5
    Replies: 8
    Last Post: 5th September 2014, 04:46 PM
  2. Advanced Equations in MMF2
    By XStar in forum Multimedia Fusion 2 - Technical Support
    Replies: 7
    Last Post: 18th June 2012, 01:45 PM
  3. Why is my 360 shooter only shooting 32 directions?
    By Wra1thus in forum Multimedia Fusion 2 - Technical Support
    Replies: 5
    Last Post: 19th January 2011, 01:38 AM
  4. Looking In Eight Directions
    By variant in forum File Archive
    Replies: 0
    Last Post: 31st December 2009, 07:49 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts