Developing Box2D game, and Introduction

Discussion in 'Public Game Developers Forum' started by XyrisKenn, Nov 23, 2009.

  1. XyrisKenn

    XyrisKenn Well-Known Member

    Nov 14, 2009
    87
    0
    0
    Developer
    Czech Republic
    Hi Forum,

    My name is Kenn, I'm in the last week of developing my first iPhone game. I hope to share it with you. It's a Cocos2D / Box2D fusion. Currently I'm tweaking the AI to produce better 'intercept' results than my math allows :rolleyes:

    The games I see on Touch Arcade are just of incredible quality. I look forward to participating.

    On the target issue, is anyone familiar with Box2D and calculating intercept code?

    Cheers!
     
  2. Flickitty

    Flickitty Well-Known Member

    Oct 14, 2009
    761
    1
    0
    iPhone Dev
    I'm not quite sure I understand what you are asking. I know a bit about Box2D and Chipmunk. I know what intercept code is, and I know how it applies to AI. However, your question lacks specifics.
     
  3. dawvee

    dawvee Well-Known Member

    Aug 14, 2009
    46
    0
    0
    iPhone Developer, DaVoid Digital
    Dublin, Ireland
    Assuming this is also your thread on the Cocos2D forums, and just going over your code, where you have:

    Code:
    if(predictLoc.x >= opponentPos.x) {
    	// go right - mod X vector
    	lateralMod = predictLoc.x; // this works very well consistently
    } else {
    	// go left - mod X vector
    	lateralMod = -(predictLoc.x); // is this correct for moving to screen left?
    }
    Is likely the problem. For moving to the left, you shouldn't need to take the negative coordinate, or really do anything different at all from moving to the right. You seem to be predicting the location accurately enough, so your value will already have the correct sign. By negating it you're making it go off. So instead you could probably take out the if/else entirely and just have:

    Code:
    lateralMod = predictLoc.x;
    The value will effectively perform the logic for you.
     
  4. XyrisKenn

    XyrisKenn Well-Known Member

    Nov 14, 2009
    87
    0
    0
    Developer
    Czech Republic
    Hi Dawvee, yes it is. Thanks for quoting the code. I didn't want to clutter up the forums too much here.

    I tried your idea, which makes perfect sense, and get an odd result with my goalie hugging screen right. The negative transformation moves my goalie to screen left ok.

    I did notice my Y values seem too high (25 say)while the X is very low, 1 or 0.9. For a lark I switched the x and y values in lateralMod and it's actually more accurate on the screen right. So my math or method is off, probably in an obvious way.

    I set up my goalie AI process like this:
    1. Calculate the predictedLocation,
    2. Make a decision according to where the puck is in relation to itself,
    3. Set up a switch statement to set a new state (Attack or defense),
    4. Make any mods to the numbers (Danger!), then
    5. Move the goalie.
    Later I'll be adding other AI modes and this helps me keep it in order.

    The game's far enough along to start posting play videos, so I'll be able to show and tell.

    Hi Flickitty, great game btw, and style. Thanks guys.
     

Share This Page