heliogame's Forum Posts

  • > nimos100,

    >

    > I am wondering what's wrong with the sequence of the following code:

    >

    > When a turretBody appeares , I want to trigger the following events:

    > 1) If turretBody is destroyed with the bullet2Player, tilemapBoxEnemy is replaced with Tilemap1

    > 2) If turretBody is not destroyed, bullet overlaps TilemapBoxEnemy and bullet is destroyed

    >

    I think the problem is in your structure of the code, meaning you are trying to do to many things in one event that would be better splitting up into several events. So there are some things that to me looks, not to good.

    Using "Create" together with other "Actions" in C2 can be a bit tricky, because you have to be careful about top levels and sub levels and know how it works to avoid problems with the "Create" action. But think everyone runs into this problem at some point.

    Your newly created object is not available before you get to a new top level. but will be available in sub levels from where it is created.

    So this will cause some problems as I see it, because you create the turretbody in a sub level, but you haven't reached a top level when using the "On collision with Bullet2Player" so the turretBody doesn't exist at this point. Another thing is the "On collision" which is a "trigger" or what to call it, indicated by the little green arrow, and it triggers whenever an collision happen that meets its condition in this case a collision with bullet2Player, so it works the same way as a mouse click on an object does. In my experience any such trigger should be placed on top level and not within a sub event. So in your case I would move the "On collision" to its own event and restructure your code so it works with it being there, and then it will most likely sort it self out.

    Yes, I previously did all three parts separately.

    The problem is that I am losing X, Y coordinates in 39 and 40 and I cannot find something to rely upon. A collision of turretBody and a bullet in 40 does not help to define old tilemap coordinates since turretBody is un objet (not tilemap). In 39, I should define again coordinates of the TilemapBoxEnemy after the objet TurretBody is created in the event #37.

    Moreover, in 39 I got a problem with priority of events. I need to make it trigger only if TurretBody (Important: TurretBody from event #37 only) is not destroyed. If TurretBody (from event #37) is destroyed, 39 event is deactivated for TilemapBoxEnemy (in X,Y coordinates of event #37).

  • nimos100,

    I am wondering what's wrong with the sequence of the following code:

    When a turretBody appeares , I want to trigger the following events:

    1) If turretBody is destroyed with the bullet2Player, tilemapBoxEnemy is replaced with Tilemap1

    2) If turretBody is not destroyed, bullet overlaps TilemapBoxEnemy and bullet is destroyed

  • nimos100, thanks a lot!

  • > By the way, I am thinking of improving the code of locating an object around the tile we hit. For instance, we have a tile and know its coordinates like Tilemap. PositiontoToTileX(bullet.X) , Tilemap.PositionToTileY(bullet.Y). How do we coordinate tiles Up, Right, Left, Down around this tile?

    >

    Since the bullet impact is always at (0,0) in tile value or what to call it, meaning this will always be by default the original tile coordinate of (TileX, TileY) regardless of where on the tilemap the bullet hit. Knowing this and looking at the image below you can see which value to add to this coordinate to get one of the surrounding tiles.

    The reason you can do it this easy, is because you convert the bullets coordinate X,Y to a tile coordinate and therefore its easier to work with.

    So in your case to get the different tiles you just add the correct amount to the TileX, TileY after the conversion:

    Top:

    Tilemap. PositiontoToTileX(bullet.X) , Tilemap.PositionToTileY(bullet.Y) - 1

    Left:

    Tilemap. PositiontoToTileX(bullet.X) - 1, Tilemap.PositionToTileY(bullet.Y)

    Right:

    Tilemap. PositiontoToTileX(bullet.X) + 1, Tilemap.PositionToTileY(bullet.Y)

    Down:

    Tilemap. PositiontoToTileX(bullet.X), Tilemap.PositionToTileY(bullet.Y) + 1

    nimos100,

    can you show a part of the code using these coordinates? I used them previously but none did not work for me. An object just does not appear. Maybe I am missing something.

  • heliogame

    "angle()" is an expression so I mean using the expression

    angle(0,0,self.vx,self.vy) [/code:3pkt25v9] when setting the angle.  Also I didn't mean using the bullet behavior.  "bullet" was just the object name I used.
    

    Got it. Thank you.

  • [quote:br3t1pi0]Strange, but it did not worked for me. Nothing happens except that Bomb object is erased.

    Does it work if you remove the "Wait 3 seconds" ?

    nimos100

    Ah, I missed "1" in the code (functionBomb.Param(1)-1) . Now , it works great. Wow. Cool.

    By the way, I am thinking of improving the code of locating an object around the tile we hit. For instance, we have a tile and know its coordinates like Tilemap. PositiontoToTileX(bullet.X) , Tilemap.PositionToTileY(bullet.Y). How do we coordinate tiles Up, Right, Left, Down around this tile?

    I just want to replace the location of objects by position

    as it seems to be not too rational.

  • R0J0hound,

    Could you precise what you mean under setting angle of motion to (0,0,self.vx,self.vy)?

    I can set angle of motion only in 0 or in self.vx (self.vy).

  • nimos100,

    Strange, but it did not worked for me. Nothing happens except that Bomb object is erased.

  • For the first one you can do it with the bullet behavior and a negative gravity I think.

    The second one you'd have to use the custom movement behavior with a negative horizontal acceleration.

    Or you can do it with just events with and object "bullet" with instance variables vx and vy

    on space pressed

    --- player spawn bullet

    --- bullet: set vx to 100

    --- bullet: set vy to random(-20,20)

    every tick

    --- bullet: add -100*dt to vx

    --- bullet: set position to (self.x+self.vx*dt, self.y+self.vy*dt)

    ^-that's to do the second picture. Fiddle with it and you can make the bullets accelerate in the other directions.

    R0J0hound, thank you. Your method with instance variables worked.

    Some nuances:

    I could not set vy to random(-20,20). It sets me 0 instead.

    Also, should we rotate the bullet separately to achieve the second way of trajectory?

  • Hi Guys, I am trying to create a gun turret that shoots like that

    Gravity and Set angle behaviors do not help much in that case. What do you think?

  • nimos100,

    There is one problem with setting a new tile to a range of tiles around the hit. As long as it is always a square that fills the whole new area, it adds unnecessary tiles like I highlighted (crossed) in your picture.

    So, imagine that we hit at what an arrow points out

    How should we deal with changing tiles without adding unnecessary ones?

    I guess we should add some kind of loop that goes through all the tilemap making a check against a tile that is not empty and then changing only those tiles, but it seems wacky combining it with functions. Uhh..

  • > Thanks nimos100,

    > Is tile 12 a red one that replaces 9 tiles?

    >

    >

    Yes this example only use one tilemap.

    Without the Capx it im not 100% certain.

    But think the wait 3 seconds might be causing the problem as you destroy the bullet, but want to pass it to the function 3 seconds later, im not certain if that is working well or how it works, as i tend to avoid waits. But you have to remember that the rest of your program doesn't pause while this wait is going on. If i remember correct objects that are destroyed will be removed from the game at the next tick. Meaning that the bullet you are trying to pass to the function doesn't exist anymore when you actually need the tile position, and since you are waiting 3 seconds which is 180 ticks a lot of things can go on in the meantime. But anyway im not 100% certain, but regardless of that, i think such situations are best to be avoided because you lack overview of whats going on with waits in your programs.

    So i would use the bomb you create to spawn at the correct Tile (Where the bullet hit) and then add a timer behaviour to that and set it to 3 second, store the Tile position in the bomb or you can generate it later when the timer is up, then use the bomb tile position with the function. Meaning you pass the bomb coordinates to the function rather than the bullet. Think that will solve the problem.

    Otherwise try to add the capx.

    I passed the bomb coordinates to the function and it worked! Thank you.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Thanks nimos100,

    Is tile 12 a red one that replaces 9 tiles?

    Here is what i tried but it does not trigger the change

    here is how it looks as the base

    and this is what i want to achieve

  • nimos100

    I am wondering how do we erase/change a range of tiles on a collision with a bullet. For instance, a bullet hits a tile, and then it should trigger a change of 8 tiles around the one that was hit. Let's say we erase those 9 tiles of tilemap 1 and replace them with tiles of tilemap 2 (the red one).

    I only managed to erase and set a tile that was hit , but no luck with erasing and setting neighboring tiles.

    Haven't read all the replies. So this might not be what you mean, but how I understood the original question. But in that case you can just ignore it

    Here is a simple example of how to get the tile.

    (Be advise that the tilemap at row 0 for both X and Y is empty so its not an error that it seems like it should be tile 3,7, its just me that didn't put any tiles in that row, so the white area around the tiles are actually row 0)

    If you want the coordinate in X,Y you can just convert the TileX and TileY to that.

  • MultipleChoice, solved! Thank you!