Need help making hitboxes for games

I’m thinking of making games in wick editor but I need to know how to make 3 types of hitboxes.


  • Barriers
    I need to know how to make barrier hitboxes that prevents the player from going to places off limits or places of the camera.

  • player hitboxes
    Pretty obvious the players hitbox showing where they can be hit.

  • attack hitboxes

Another obvious one a small box showing where entities can be hit

If not all of these can be solved its okay

so the hitbox, hurtbox, and out of bounds mechanic?

Yes I just don’t know how to code it…

If you want to make Barriers create your player and barrier and turn them into clips. Name the player whatever you ,want and the barrier what ever you want. Then click on player and add an Update script and write:

if(this.hits(barrierName)) {
(code goes here)
}

In the (code goes here), section,you can put:

this.x -= 5 to stop the player if they try to go to the right.

this.x += 5 to stop the player from moving left.

this.y -= 5 if you want a barrier below the player to stop them from being able to go down.

this.y += 5 if you want to have a barrier ontop of the player, this way the barrier stops the player from going up.

Just make sure that the number or variable after the = is the same as your player speed so it doesn’t bounce or phase through.

You can just make a ‘hitbox’ layer (which should be on top) and make this code:

const allclips = project.timeline.layers[0].activeFrame.flatMap(f => f?.clips);
const hitclips = allclips.filter(c => this.hits(c));

// now, you can filter `hitclips` with anything. Example: you can make 'point clips' which give points to a score using:
this.givesPoints = 15 // point clip

// player clip
const pointsToGive = hitclips.filter(c => c?.givesPoints).map(c => c.givesPoints).reduce((acc, cur) => acc + cur, this.points);

this.points = pointsToGive;
1 Like

thank you!this really helps

Hey, reminder that the barrier code isn’t really good. I’d make a ‘barrier layer’, which contains barrier clips.

const myArrOfClips = [new Wick.Clip];

myArrOfClips.forEach(function(that) {
  if(this.hits(that)) {
    this.x = this.lastX; // always store the last X and Y values before changing them.
    this.y = this.lastY; // Same as the last one
})
2 Likes

:+1: (i need these parentheses to post)