• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
ewaldhew

Circular Playing Field

6 posts in this topic

Hi all,
 
I am currently making a 2D shooting game, but have gotten stuck trying to solve this one problem.
 
I have a circular playing field, which is the area the player (or other entities) is allowed to move around in. However, I have tried all the method I could think of, and searched the forums here in an attempt to find anything useful, but did not. I have no problem with detecting when the player is on the boundary, but restricting the player within it is the problem for me..
 
What I wish to achieve is that the player will hit the wall and, if it is not on any of the eight cardinal or ordinal "corners" of the circle, slide towards it. So, for example, if the user held down [up] and [left], the player would move northwest until it hits the wall, then continue to slide along till it is at the northwest position on the circle.
 
Illustration of my point (I hope it is clear enough):
 
circular.jpg
As can be seen, my idea was to calculate an opposing force r. So, in this example, ry cancels out the player's y velocity, but the player continues to move leftwards. So as the player moves towards northwest, rx grows larger and eventually cancels out the player's x velocity too making that the final resting position.
 
I am not sure if there is any flaw in this approach itself, or that my method of computing rx and ry were wrong. Here is my most recent try:
[spoiler]
if (distance(me.sprite.position.x, me.sprite.position.y, 300, 300) >= 150)
{
    if (_controls.pressing.up)
    {
        ry = -me.speedY;
        if (_controls.pressing.left) //2ndQ
        {
            if (me.sprite.angle != -Math.PI/2)
                rx = ry*Math.tan(me.sprite.angle);
        }
        else if (_controls.pressing.right) //1stQ
        {
            if (me.sprite.angle != -Math.PI/2)
                rx = ry*Math.tan(Math.PI/2 - me.sprite.angle)
        }
            else rx = 0;
    }
    else if (_controls.pressing.down)
    { etc...

    }
}
            
me.speedX += rx;
me.speedY += ry;
Note: distance() calculates the distance from (300,300)[the center of the window] to the player's position.
angle is the angle from the center (as marked in the diagram above)
I tried putting up/down and left/right together at first, but after that failed I tried to calculate separately for each quadrant, which obviously did not work either.
[/spoiler]
My maths isn't that good, so I am really out of ideas. If someone could give me any help it would be greatly appreciated! Thanks.
0

Share this post


Link to post
Share on other sites
This is basically "wall sliding". Except instead of a straight wall with a single normal vector, you have a curved surface with the surface normal being dependent on where you hit it (and pointing to the center of the playing field).

If you google "collision detection wall sliding" you can probably find some helpful info.
0

Share this post


Link to post
Share on other sites
Move the player as normal. If the distance from the centre to the player is greater than the maximum permitted, move the player directly back towards the centre by the excess amount.

Angles and trig functions are not required. All you need is the vector from the centre to the player. There's also no need to mix the movement code and the collision code.
2

Share this post


Link to post
Share on other sites
Thanks for all the input, I finally solved it.
However, one problem remains, is that the movement seems...jagged, for lack of a better term, as if the curved wall was actually made of steps.

EDIT: I fixed the jagged movement too, thanks again for the help =D Edited by ewaldhew
0

Share this post


Link to post
Share on other sites

Thanks for all the input, I finally solved it.
However, one problem remains, is that the movement seems...jagged, for lack of a better term, as if the curved wall was actually made of steps.

EDIT: I fixed the jagged movement too, thanks again for the help =D

Glad you figured out the solution, now tell us how you fixed it! :]

0

Share this post


Link to post
Share on other sites

Well, I basically sat down and considered carefully the four possible cases (in each of the four quadrants) and figured out that if the player was on the right half (?/2 < ? < -?/2) of the field, rx would be -rcos? and rwould be -rsin?, where r is the player's resultant speed (playerspeed for horizontal/vertical movement, and sqrt2*playerspeed for diagonal). Then, on the left side, rx = rcos(?+?), ry = rsin(?+?). What I was doing wrong before was, as you can see from the bit of code in my first post, not computing r at all, and using tan, as well as getting Newton's Third Law wrong. Now that I got my maths(and physics) figured out, it works exactly as I wanted it to. 

 

Also, the jagged movement was due to me forgetting to add in the code to restrict the player's position. So the player would move outside the boundary momentarily before being pushed back in by the restoring force.

 

In conclusion, I was not thinking straight at all before, and adopted a totally illogical approach =\ I still feel kinda dumb even now D:

1

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0