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

Jumping for AI in my platform game

10 posts in this topic

Hi GameDev!

This is my first post here ^^

Now to le business.


The problem:
I have a side-scrolling-platform-game where you have 2 characters. The first one is the one you are in controll of. He is ready and done with all the controlls.
Then we have the enemy, lets call her Sarah.
Sarah will be at the left on the screen throwing stuff at you, and when you get close enough she will either walk or jump to the next waypoint in her waypointlist.After that she will continue to throw stuff at you. That is, untill you get close enough, then she will either walk or jump to the next waypoint and so on and so on.

My problem here is that i want to create a code for her jumping. i will have set of waypoints which will have 1) coordinates for the next place she wants to go and 2) if a jump is needed or not.
But i cant seem to find anywhere a similair code for that.
I've looked at parabola equations ([url="http://www.wolframalpha.com/input/?i=y+%3D+%28x%5E2%29+%2F+%284+*+a%29+where+a+is+-1"]http://www.wolframalpha.com/input/?i=y+%3D+%28x%5E2%29+%2F+%284+*+a%29+where+a+is+-1[/url] and [url="http://www.wolframalpha.com/input/?i=parabola+formula"]http://www.wolframalpha.com/input/?i=parabola+formula[/url])
And also the throwing equation you learned in physics courses at high school ([url="http://www.wolframalpha.com/input/?i=y+%3D+%28V0+*+sin%28a%29+*+t%29+-+%28%28g+*+t%5E2%29+%2F+2%29"]http://www.wolframalpha.com/input/?i=y+%3D+%28V0+*+sin%28a%29+*+t%29+-+%28%28g+*+t%5E2%29+%2F+2%29[/url])

But I really can't seem to get a code where she jumps EXACTLY to the place i have in her waypoint-vector..


So the variables i have from the beggining och the jump are:
The distance in x.
The distance in y at the top (i will have the difference in Y in the the platforms + 128 pixels as a top for the parabola).

Asides from those two, i have tried to experiment things like starting veclocity in x and y, gravity and at which time (in frames) the jump would take.


Can somebody please give me either a code for this, a good site about this or something else useful i would be forever grateful!

Cheers!
/TheCalm
0

Share this post


Link to post
Share on other sites
I'm really getting frustrated here guys :C
Doesn't anyone have any idea? :/

Cheers, TheCalm
0

Share this post


Link to post
Share on other sites
Just add a boolean variables to your waypoint-edges. like this:
struct Waypoint
{
vec pos;
}
struct edge
{
Waypoint w1,w2;
float distance;
bool jumpNeeded;
}

I hope this helped you :D
0

Share this post


Link to post
Share on other sites
Thx for the reply!
Though i'm afraid that's not my problem. I already have a class for the waypoints who contains a position-vector and a bool that keeps track if i need to jump.

The problem is the get a formula to get Sarah to jump and land exactly on the position :/

Cheers!
0

Share this post


Link to post
Share on other sites
I don't have time to write code for you, but here are some ideas for getting more information into your equation and simplifying the problem.

1) Keep in mind that there may be many jump angles/velocities that land you in the same spot. You can simplify by locking your angle to 45 degrees. (or whatever angle works best for you)

2) If you know the maximum height of your arc, and your acceleration due to gravity, then you also know the time it takes to rise to that point.


3) You posted a lot of formulas you're looking at, but i find diagrams and descriptions a little easier to convert into code:
[url="http://www.physicsclassroom.com/Class/vectors/u3l2c2.cfm"]http://www.physicsclassroom.com/Class/vectors/u3l2c2.cfm[/url]


I'll post more when I have time if this was too cryptic :-)
0

Share this post


Link to post
Share on other sites
Your problem looks hard,hope someone who have professional experience can really help you.
Good luck![img]http://public.gamedev.net//public/style_emoticons/default/biggrin.png[/img]
0

Share this post


Link to post
Share on other sites
[quote name='sox' timestamp='1331062654' post='4919874']
I don't have time to write code for you, but here are some ideas for getting more information into your equation and simplifying the problem.

1) Keep in mind that there may be many jump angles/velocities that land you in the same spot. You can simplify by locking your angle to 45 degrees. (or whatever angle works best for you)

2) If you know the maximum height of your arc, and your acceleration due to gravity, then you also know the time it takes to rise to that point.


3) You posted a lot of formulas you're looking at, but i find diagrams and descriptions a little easier to convert into code:
[url="http://www.physicsclassroom.com/Class/vectors/u3l2c2.cfm"]http://www.physicscl...tors/u3l2c2.cfm[/url]


I'll post more when I have time if this was too cryptic :-)
[/quote]

Thanks!
I've been trying to get a good formula from what i know. But i cant get it to be exact. The problem is that it seem to be dependent on to many variables.

For instance we have one formula that says that the speed in the x-axis is the same, it never changes. So if we have that in mind we know that:
X (a distance) is equal to V0 * cos(a) * t
Where V0 is the starting velocity, the cos(a) i the cos for the angle at the start and t is the time it takes to travel the distance in x.

Okey, so we can rewrite cos(a) to be V0x / V0 which leads to "x = V0 * (V0x / V0) * t". We see that we can take away the "V0" part leading us to get:
"x = V0x * t". This is good, since I know my velocity in x to be the same all the time which means that the v0x is the same.

So we know x, since we have a waypoint that keeps track of the points we want Sarah to go. Perfect you might think! But it is here that it gets tricky. Why?

I'll try to explain.


So say that x is 200. That means Sarah is supposed to jump 200 pixels from her place here. Her speed in the x-axis must be atleast 11 (since my character im steering has 10 in speed, and i want Sarah to be faster then my character).
So this will give us the time for the jump.
In this case this means that the distance of 200 pixels with a speed of 11 pixels per update (i will refer the time as how many updates something will take. And my FPS is locked at 60 FPS, giving us 60 updates per seond. If you would rather count it as pixels per second or something).
Anyhow! This means that the jump will take 200/11 = 18.18181818... ~18.2 updates.


We also know that "y = V0 * sin(a) * t - ((g * t^2) / 2)
Where y represents the point at any time in the jump in the y-axis, the g is the gravity and the sin(a) is sin of the angle.
We can rewrite sin(a) as V0y / V0.
And as above this will lead to "y = V0y * t - ((g* t^2) /2).
Now we have three loose variables. The starting velocity V0y, the gravity g and the y.
But if we say that we will take the point where y is the highest, then we know that would be exactly the half of the time (18.2 updates).

And say that we take y to be "the difference in y + 128". Meaning if sarah will jump in the same y height, her maximum height will be 128 pixels above her position now. If she were to jump to a platform 64 pixels above her, her maximum height would be 128+64 = 192 pixels and so on. But for now, lets just focus on a jump 200 pixels away in the same y-height. This will give us y = 128 at the time of (18.2 / 2) = 9.1.


But the problem now is that we still have two loose variables, g and V0y, right?
0

Share this post


Link to post
Share on other sites
Your system should have a constant g, should it not? Your entire world would have some form of gravity, and your character that is finished will probably be using the same constant. [s]At mid jump, the apex, your V0y would be 0. At the start and the finish, your V0y would be 0. Mid-jump, your V0y would be your previous Vy. I may be wrong on that very last statement, but I don't think so. If V0y was to consider your initial jump's starting velocity, the character is not moving, so that would fully eliminate V0y * t.[/s]


EDIT: As an afterthought, and due to it being late, V0y would be a function included in your equation for y, and each point during the jump would recalculate the equation with a different t: y = (g * t + V0y) * t - ((g * t^2) / 2) where V0y is the very first velocity you want to give the character to jump.

-- To clarify: (g * t + V0y) is the velocity the character is at at the end of the last update.
1

Share this post


Link to post
Share on other sites
[quote name='Dragonsoulj' timestamp='1331275330' post='4920595']
Your system should have a constant g, should it not? Your entire world would have some form of gravity, and your character that is finished will probably be using the same constant. [s]At mid jump, the apex, your V0y would be 0. At the start and the finish, your V0y would be 0. Mid-jump, your V0y would be your previous Vy. I may be wrong on that very last statement, but I don't think so. If V0y was to consider your initial jump's starting velocity, the character is not moving, so that would fully eliminate V0y * t.[/s]


EDIT: As an afterthought, and due to it being late, V0y would be a function included in your equation for y, and each point during the jump would recalculate the equation with a different t: y = (g * t + V0y) * t - ((g * t^2) / 2) where V0y is the very first velocity you want to give the character to jump.

-- To clarify: (g * t + V0y) is the velocity the character is at at the end of the last update.
[/quote]


Thanks :)

The problem is that even though i set a constant "g" and a constant "V0y" the jump doesnt seem to land on the exact position i want to. Sarah seem to land to far :/
0

Share this post


Link to post
Share on other sites
Like what one poster said you could simplify things by making some variables constant. But you could make it even easier by making almost every variable constant. Restrict yourself to a limited set of jump vectors and have the AI choose from among set one vector that best fits the situation.
0

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