How do I create hitbox instances?

0 favourites
  • 7 posts
From the Asset Store
Fully commented source code/event sheet & sprites to create a space shooter game
  • Hi all.

    I have been trying to find an answer but could not figure it out. Would love some advice and thanks in advance!

    So basically as topic title suggested, I have a character who does 3 punches combo and I'm trying to create a hitbox for each of these punches. I could spawn the same hitbox but since they are best done different in sizes I thought one method is do create instances (that are difference in sizes) of a hitbox and spawn them accordingly with an instance variable.

    However I can't seem to specify a specific instance with their instance variable (eg. hitbox_number =2), they are all spawning the same one. (See screenshot)

    If anyone can help out a stuck fellow here would be appreciated. Thanks guys.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • try to change the trigger once to loop 2 or 3 times on how many times you need to spawn a hitbox when the animation is between those frames or is playing, then create object and set hitbox_nr to loopindex+1.

    also animation frame 0&1 = 01= 1 i think. so it will only trigger when frame = 1. the & in construct is like (this item bound with this item (not added as in math but as a condition like [this item and this item]).

    which is not what you are trying to say there i think, which is when is 0 or 1. for that you can compare variable if it's between values. lower bound being 0 upperbound being 1.

  • Right click, Clone the object type, and place it and it will out rename for you.

    hitbox_number

    hitbox_number2

    hitbox_number3

    Is that what you mean?

  • GeorgeZaharia

    Thank you! Your suggestion on animation frame totally make sense, i'll try that out.

    Thanks for the help, unfortunately not exactly what I meant, but glad im on the right track. I have already cloned the object in the level design, so each of them already have a different name on their instance variable: hitbox_number01, hitbox_number02, hitbox_number03 etc.

    What I hope to do is that during the melee combo (there are 3 moves):

    In first attack animation (during frame 1)> Spawn hitbox_number01

    In second attack animation (during frame 0&1)> Spawn hitbox_number02

    In third attack animation (during frame 02 for example) > Spawn hitbox_number03

    As each of them varies in size.

    I hope that make sense :) Thanks guys!

  • u can replace the 0&1 with lower or equal to 1 =< meaning, if the animation is at frame 0 or 1 it will spawn a hitbox if that is what you want, but then ul have 2 hitbox created or more, depending on the delta time trigger.

  • Thanks GeorgeZaharia, It seems I can spawn the same hitbox in the two different frames of the animation now. But what if I want to spawn another hitbox after that, that has a different width and height to the first one? How should I achieve that?

    Thank you again

  • when you create the hitbox immediately after the action that is

    "create hitbox at XY layer 0" or if you use

    "object.Spawn object at imagepoint 0"

    under it you can add the following action set hitbox size : width = hitbox.width + random(10,-10) Height = hitbox.height + random(10,-10)

    that will make all the hitbox created have different size, you can change the 10 , -10 to whatever value you want.

    that way you create either rectangles or squares but if you want to keep the aspect ratio of the hitbox in case u want all to have a square look or initial size, but only like make them smaller or bigger without warping the initial shape u use hitbox.set scale to random(0.8,1) where 0.8 is 80% of the initial size and 1 is 100%.

    and random(n1,n2) picks a random value between those numbers.

    the same way if you have different animations for hitboxes, you change the animation by adding another action under like

    hitbox.setanimation to choose("animation1","animation2","animation3") but you have to have those animations inside the sprite object hitbox.

    if you want to change the frame in case you have only different frames, like different shapes stars, circles, squares etc. u use

    hitbox.setanimationframe to floor(random(0,hitbox.animationframecount-1))

    for the animation frame change you need to disable or set the animation speed that contains those frames to 0 so they don't change after u set them.

    where hitbox.animationframecount is the total number of frames you have inside that animation for the hitbox, but construct counts from 0 and hitbox.animationframecount counts from 1 so you have to subtract 1 in order to get the right total frames count based on Construct's counting system.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)