1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Hey Guest, is it this your first time on the forums?

    Visit the Beginner's Box

    Introduce yourself, read some of the ins and outs of the community, access to useful links and information.

    Dismiss Notice

[Solved] Tools to help debugging positioning and other relative matters

Discussion in 'Modding Help' started by Vermilicious, Jan 29, 2016.

  1. Vermilicious

    Vermilicious Ballista Bolt Thrower

    Messages:
    232
    I've been tinkering with a onCollision function and is struggeling a bit with figuring out exactly what's happening. Looking through various code, I came across the GUI::DrawArrow2D call, which would seem useful to find out what's going on in this case. However, I don't see anything drawn when I call this. Can anyone shed some light upon the matter? Do I have to enable something somewhere? Is there any other tools available perhaps? Are there any server variables that could be useful? The most interesting things to check for, I think, is highlighting points, lines between points,circles (radius), highlighting tiles and highlighting blobs.

    For those curious, I want to detect when a zombie blob collides with wood blocks, but the parameter values passed to onCollision very rarely point at the wooden block I'm trying to do things with (damage). With blobs everything is just peachy. Oh, and the zombie blob collides with everything.
     
  2. Asu

    Asu THD Team THD Team Forum Moderator

    Messages:
    1,580
    All functions namespaced in GUI has to be run in the void onRender hook. This is because of how the engine behaves (and it's pretty much the same as every game engine).
    onCollision is called once when blob X collides blob Y.
    onEndCollision is called once when blob X stops colliding blob Y.
    The first argument, this, refers to the blob used in the script, and blob to the other one.
     
    makmoud98 and Vamist like this.
  3. Verrazano

    Verrazano Flat Chested Haggy Old Souless Witchy Witch Witch THD Team Global Moderator Forum Moderator Tester
    1. Practitioners of War Extreme Revolution - POWER

    Messages:
    477
    if you want to detect the collision between a blob and a block make sure you are using the correct onCollision hook. onCollision(CBlob@ this, CBlob@ blob, bool solid, Vec2f normal, Vec2f point)
    if the blob is null and solid is true. Then you can check the tile type at Vec2f point.
    I would suggest printing this out rather than keeping a state and drawing it in onDraw as it will be less work.
    I think what you want in terms of drawing though is provided by g_debug, simply set this variable to 1 it can be found in autoconfig.cfg
     
    Asu likes this.
  4. Vermilicious

    Vermilicious Ballista Bolt Thrower

    Messages:
    232
    Thanks for the quick replies guys.

    It does indeed make sense to do GUI calls in onRender, but the requirement to do so wasn't obvious. It would seem that nothing is drawn even if I do that though (I store the necessary variables with the blob). I can't seem to find any missing initialization either. Seems I'm missing something.

    As for the function, it is the hook you mention, Verrazano, and I figured that the boolean told what it was. I've been checking the normal vector being passed to determine which direction blob collisions occurs, and it works well. But for tiles, it isn't working as expected. Here's the code snippet:
    Code:
        //Retrieve a reference to the map object
        CMap@ map = this.getMap();
    
        //Obtain a tile object
        Tile tile = map.getTile(point1);
    
        //Check if tile type is wood
        if(tile.type == CMap::tile_wood) {
    
          //Initiate tile destruction
          map.server_DestroyTile(point1, 0.1f, this);
    
        }
    The wood tiles only very rarely collides, and it's rarely the tile I expected.

    (On a side note, I haven't yet fully understood how the script run flags works yet. Could there be some relevance there?)

    The debug variable certainly was nice, but it doesn't seem to visualize collisions.

    Update:

    The reason I wasn't seeing anything even after moving it to onRender, was simply because I was not converting to screen references with getScreenPosFromWorldPos. Duh! Here's the simple helper I wrote:

    Code:
    void onRender(CSprite@ this) {
    
      if(g_debug > 0) {
    
        //Obtain a reference to the blob object
        CBlob@ blob = this.getBlob();
    
        //Retrieve screen position for this blob
        //COMMENT: Alternatively use a saved position at the time of collision
        Vec2f thisScreenPosition = getDriver().getScreenPosFromWorldPos(blob.getPosition());
    
        //Retrieve screen position for collision
        Vec2f collidedWithScreenPosition = getDriver().getScreenPosFromWorldPos(blob.get_Vec2f("collidedWithPosition"));
    
        //Draw an arrow
        GUI::DrawArrow2D( thisScreenPosition, collidedWithScreenPosition, SColor(0xffdd2212) );
    
      }
    
      //Finished
      return;
    
    }
    Well, in any case, I'm now seeing that what I was assuming is incorrect. As AsuMagic pointed out, these collision events are fired only once. I need to go about this in a different way. An onTouch hook or something similar, would be what I want.
     
    Last edited: Jan 29, 2016
  5. Verrazano

    Verrazano Flat Chested Haggy Old Souless Witchy Witch Witch THD Team Global Moderator Forum Moderator Tester
    1. Practitioners of War Extreme Revolution - POWER

    Messages:
    477
    You can always just do a tile type check by some offset from the blob during onTick, just do it on every 15th frame or so as to not lag the game with lots of those blobs.
     
  6. Vermilicious

    Vermilicious Ballista Bolt Thrower

    Messages:
    232
    Yeah, I guess that's the way to go.

    Thanks for the help, guys. I'm tagging this as solved, but if anyone's got any other tips to debugging stuff, don't be afraid to say something :o)
    --- Double Post Merged, Feb 16, 2016, Original Post Date: Jan 30, 2016 ---
    Is there any documentation on the GUI class/namespace? In particular, is there any method for drawing circles? I've not been able to find any such calls in vanilla code, but in debug mode circles are drawn around blobs for instance. Would be neat to have this ability from scripts also.