• 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
Esper S.

Jumping - What did I do wrong?

10 posts in this topic

I know it would be easy to use the windows timer, implement gravity and acceleration, and etc. but just as a test I tried making a primitive "jumping function". On run, the computer freezes; my guess is that I'm doing a useless loop of some sort. Here is the code; can anyone help figure out the problem?

void Character::Jump(bool x){
 bool inAir;
 bool rising;
 bool falling;

 if(m_pos.y != 0)inAir = true;
 if(x)inAir = true;
 if(inAir){
  if(m_pos.y == 10 && !falling){
   rising = false;
   falling = true;
  }
  if(rising)m_pos.y += 0.5;
  if(falling)m_pos.y -= 0.5;
  if(m_pos.y == 0){
   inAir = false;
  }
 }
}

I've tried many ways, and this is my latest... I can't see why it shouldn't work unsure.png

0

Share this post


Link to post
Share on other sites

1. This code can't loop by itself. 

2. If your computer freezes, it's more likely that you have corrupted your memory than an endless loop. (Unless you mean that your game freezes).

 

Since there is not enough code to analyze this, my suggestions are:

1. Use a debugger, and break excution (see where your computer is stuck).

2. If a debugger is unavailable, add some printf's and print the character ID + the character state. You should be able to figure out what's wrong. (Dump it into a log file)

3. Post more code, so someone can figure out your problem.

 

You should really try suggestions 1 & 2 first, unless you want to wait for someone to figure out the problem.

1

Share this post


Link to post
Share on other sites

Oh, I thought I laid it out to be understandable enough sad.png Well the whole thing is simply a jump function to execute on a camera. It is safe to assume that all other translations/rotations are already coded, so lets just focus on the 'jump' function. bool x is made true when the user presses a key (whichever one you want tongue.png ), and Jump(bool) is run every frame. In case it's the m_pos part that's worrying you, m_pos is a D3DXVECTOR3. Now, with all that out the way, I just want to restate that this is not in any way how I would code a jumping function; this is just something fun I wish to try out to see if it works. The goal is to make basic code that uses no timers, no acceleration, and no gravity: a basic jump function biggrin.png

 

Ah, one more thing: I am using DirectX10, if it helps. But since this is just practice code, the DirectX/OpenGL version used doesn't matter; only making it work with the constraints.

0

Share this post


Link to post
Share on other sites

Here's a hint: when the player presses a button, inAir is set to true, but what are the values of rising and falling?

2

Share this post


Link to post
Share on other sites

Using all that "if" makes things longer to create and organize

 

remember that bool is a byte so it can have a value from 0 to 255.

 

it will be better if you use just one variable -unsigned char- that is one byte too and when the value of this char is

0 it means it is falling

1 it means it is in air

2 it means its falling

3 it means it is in air and falling

etc..

 

I don't know well what are you doing but you get the idea

it will be easier this way

1

Share this post


Link to post
Share on other sites

Here's a hint: when the player presses a button, inAir is set to true, but what are the values of rising and falling?

     I'm such an idiot!laugh.png I should have defined the three bools in the header for this kind of operation. Also, BLM768 was spot on. Since the player will rise on button press, both rising and inAir should become 'true'. Furthermore, since rising and falling are (pretty much) opposites, only one was required. I believe this is what Iomateron was getting at. Here is the finished code for a basic jump biggrin.png - who knows, someone might find it helpful:

//remember to declare "bool inAir, rising;" in your header. On initialization, just set them to false;
void Character::Jump(bool x){
 if(m_pos.y != 0)inAir = true;
 if(x){
  inAir = true;
  rising = true;
 }
 if(inAir){
  if(m_pos.y >= 10)rising = false;
   if(rising)m_pos.y += 0.5;
   if(!rising)m_pos.y -= 0.5;
  if(m_pos.y == 0)inAir = false;
 }

Nice work guys! (y)

0

Share this post


Link to post
Share on other sites

You should initialize all of your bools, if not they'll just have garbage that will most likely be non-zero, which is always true. Just set them all to false.

 

Your first check is likely to always be true, given that you've got a velocity applied somewhere. You might want to make it " m_pos.y > 0"

if(m_pos.y != 0)inAir = true;

Same with your max 'y' check, for one, you don't even need the '!falling' in there, because you haven't even touched it yet.

if( m_pos.y == 10 )
 
// Should be
if( m_pos.y >= 10 )

Again this check is useless, you've only assigned to 'rising' once and you set it to false when you did that.

if(rising)

 

Basically everything here that you're doing is wrong or a bad way of doing it.

 

Those booleans that you have should be static, or preferably a data member in your moving object.

 

If you do that then you may find this to be a bit easier than you think.

Edited by Muzzy A
0

Share this post


Link to post
Share on other sites

@Muzzy A
  The code has been remade and re-posted  smile.png (see comment right before yours)

0

Share this post


Link to post
Share on other sites

if(m_pos.y != 0)inAir = true;  <------this kind of code can be transformed

 

inAir = (m_pos.!= 0) ;  <----to this

2

Share this post


Link to post
Share on other sites

@Muzzy A
  The code has been remade and re-posted  smile.png (see comment right before yours)

You still have this

if(m_pos.y != 0);
 
// Should be
if(m_pos.y <= 0);

Though you're only adding or subtracting '0.5', in an actual game/project time is a factor and '0.00001 != 0.0', just a heads up. It will only work in your case.

 

 

I had to stop myself from writing a tutorial :P

Edited by Muzzy A
1

Share this post


Link to post
Share on other sites

if(m_pos.y != 0)inAir = true;  <------this kind of code can be transformed

 

inAir = (m_pos.!= 0) ;  <----to this

 

I like that! huh.png

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