Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
[Box2D]Need help experience create "Ninja Turtle" platfrom game using box2d — Gideros Forum

[Box2D]Need help experience create "Ninja Turtle" platfrom game using box2d

DungDajHjepDungDajHjep Member
edited September 2014 in General questions
anyone can help me answer some question ?

I want create game platform same here:
http://www.kongregate.com/games/urbansquall/tmnt-double-damage
and have some question:

1. when bot saw me (or i saw bot in monitor) him start working and shooting me ? ( use one ray casting per one bot ? or querry AABB ?)
2. How to enemy know me left or right him ?
3. How to check damage colission when slash enemy or enemy slash me ? (create a body or fixture near atacker for check colission when slash ?)
4.When me jumping and rotation same contra, body is small than ?
5.Make a querry AABB move with a body is not effect performance ? i do that in onEnterFrame and i guest it's make 60 querry AABB per second ???
6. i want pooling body enemy and re use it, how i can found where i will set position for body i will re use

Comments

  • tkhnomantkhnoman Member
    edited September 2014 Accepted Answer
    1. You don't need to do Box2D related function for this. Just check whether range between Player and Enemy are < than a number.
    2. Same with 1, move according on Player x and Enemy x difference.
    Check on every enterframe, then use attached "Range fixture" to let the Enemy attack when Player is on Range.
    3. Probably using AABB is the best solution, but i sometime also use a body, it depends whether you want it to stay for what millisecond, if it's instant, AABB is the best choice.
    4. You can attach 2 Fixture to player, with jump size and stand size.
    And on Collision, check whether player is jumping or not by a variable.
    5. Fire AABB only if needed, or if Player / Enemy within fixture range. Timedly.
    It's still fine if you fire AABB for 3 enemy onEnterFrame, as long as destroying & creating body is not always in the function.




    Likes: DungDajHjep

    +1 -1 (+1 / -0 )Share on Facebook
  • DungDajHjepDungDajHjep Member
    edited September 2014
    thanks @tkhnoman but i not really understand question 1 and 2, if i have some enemy, i need get all enemy position and compare it with player position onEnterFrame ?
    i think it;s not good for performance than ray casting ?
    3,4,5 accepted
    additional q6: i want pooling body enemy and re use it, how i can found where i will set position for body i will re use
  • tkhnomantkhnoman Member
    edited September 2014 Accepted Answer
    Comparing variable to another variable onEnterframe won't affect performance that much, or even at all.

    I don't really know why you choose raycasting for that.
    Raycasting is used usually for "shoot path checking" or something like that. Whenever it fires, it check every fixture that collide with the line that we provide (without any filter), then on function return, it obtain hitXY position, fixture, and even the vector of the line collided.
    When you look at that, of course it consume more proccie.

    I did many game before, even you compare 50++ enemy on screen, on enter frame, and change their Velocity each enterframe, even scale and alpha on MovieClip function, it won't affect performance.
    So just compare their X ( getPosition() ) onEnterFrame, with the character.
    You can try it yourself.

    if you have trouble regarding enterframe, you can check my comment here:
    http://giderosmobile.com/forum/discussion/comment/38447#Comment_38447

    (Compare enemy variable with character on enemy:update() on that comment)

    The most affecting for perfromance (in this case, since it side scrolling) is that you need to manage visible object.
    In this case, Gideros "still" render all object that have visible on, even with alpha==0
    So you need to setVisible(false) to any object that doesn't appear on screen bound.

    ------------------------

    6. Just set the Body (with timer) body:setActive(False), and also use a variable to set the body as disable.
    You might also want to add Enemies inside a look-up table.

    table.insert(enemyTable,enemy)

    And on reactivating of the same enemy, just activate the body, reset all variable(hp,pos,visibility,etc). You can check which enemy inactive with this kind of function:
    local enemyFound 
    for k, enemy in pairs(enemyTable) do
    if enemy.inactive then --- variable inactive set true on enemy removal
    enemy.inactive = nil
    enemyFound = enemy
    break
    end
    end
     
    if enemyFound then
    ---reset all variable here
    end
    +1 -1 (+2 / -0 )Share on Facebook
Sign In or Register to comment.