• 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
dacypher22

Beginner help: Making a curved path for object in 2D.

5 posts in this topic

I am not sure if I should post this here or in the beginner section. I have search extensively, but am wondering if I just don't know what the name of the solution I am looking for is.

Anyway, I am trying to make an object (a ball) move from point A to point B, but curve along a path to its destination. This is all in 2D. I am familiar with trig (just completed it in college last fall semester), but I have seemed to have a problem converting that knowledge to a game. I did some looking around, and most of the topics related to Bezier curves, which I am pretty sure I don't need, and hermite curves, which may be what I need. Is there a more simple way to do this? I always want the ball to end up at point B, but I want to allow the player to select how wide the curve will be, up to a point.

Does anyone know of any tutorials for this, or just good general 2D game math tutorials? Most everything I have come across is for 3D, which I know contains a lot of good info for 2D, but really clouds things up, particularly when I don't know what is relevant to me or not. Thank you in advance!
0

Share this post


Link to post
Share on other sites
You need to be more specific. There are an infinite number of 2D curves that pass through two points so to decide on a type of curve you need to think about what kind of curve you want and how to specify it in terms of mathematical constraints. For example, do you need the ball to start out in a particular direction, end up moving in a particular direction, and also pass through a particular point along the way?

If you just want any curve, then pick something really simple like a parabola.
1

Share this post


Link to post
Share on other sites
Oh, no the points it passes through are not important. Only where it starts, where it ends, and the amount of curvature (defined in the game by the number of times the player presses left or right before launching the ball). So a parabola sounds good. But I don't really know how to convert that to a path the ball can follow in the game. I guess I am kind of suffering on the [i]applications[/i] of trig and other math types, particularly for games. I always used y^2 = 4ax to make a parabola. But I don't really know where to go from that, or if that is even the right parabola formula, since I know there are several. I guess I don't know how to take that and actually work with it in terms of an angle, starting location and ending location. Thanks!
0

Share this post


Link to post
Share on other sites
Here are some equations about the parabola in general:
[url="http://en.wikipedia.org/wiki/Parabola#Equations"]http://en.wikipedia....abola#Equations[/url]

For fun, try plotting this somewhat arbitrary equation on wolframalpha.com with various parameters... Where d is the distance between the start and end points on the x axis, and h is the height of the "parabola" on the y axis:

y = a(-x^2 + b) = -ax^2 + h
b = (d/2)^2
a = h/b

For instance -- if my math is right -- where d = 8 and h = 5, you get the equation y = (5/4^2)*(-x^2 + 4^2) = -(5/4^2)*x^2 + 5. This "parabola" reaches a maximum height of y = 5. This "parabola" intersects with the y = 0 line at x = -4 and 4, which gives a total distance of 8. Hope that gives you some help. You can use the derivative of the equation to calculate the slope-angle of the "parabola" at the starting point -- that is, the derivative dy/dx = -2ax gives a slope of 2.5 for x = -4. Note that converting between slope and angle is given by A = arctan(slope), which in this case is A = arctan(2.5) = 68.19 degrees for x = -4. For fun, note that as the height h goes to infinity, the angle should go to 90 degrees. Likewise as h goes to 0, the angle should go to 0. Now, on the other hand if you start with a desired angle A and a desired d (which seems to be your case), then you can reverse calculate h from those by doing some algebra to get something like h = 1/4 * d * tan(A). Have fun, and of course be aware that tan/arctan generally work in radians, where I worked in degrees here. No big deal. Also, of course your start point and end point might not be centred around the x origin, but that's just a matter of translation before and after the calculations.

If you really want to get involved with angles and this is all getting more complicated than desired / not true enough to a parabola for you, then maybe the plain old SUVAT equations are what you want.
[url="https://sentynel.com/media/old/equations.html"]https://sentynel.com.../equations.html[/url]
[url="http://www.physicsforidiots.com/dynamics.html"]http://www.physicsfo...m/dynamics.html[/url] Edited by taby
1

Share this post


Link to post
Share on other sites
Bezier curves are really nice curves and easy to implement.

More can be found here: http://en.wikipedia.org/wiki/B%C3%A9zier_curve

More technical definition can be found on Wolfram Mathworld: http://mathworld.wolfram.com/BezierCurve.html
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