How can I put a hitbox on something, so my game character can’t pass through it?
Thanks!! I needed a code of the one that acts like a real wall
Happy to help!
Click to view code
//Type the code below into the update script for the wall.
//Replace the word “player” with the name of your player
if(isKeyDown('right')){
player.x+=5;
if(this.hitTest(player)){
player.x-=12;
}
}
if(isKeyDown('left')){
player.x-=5;
if(this.hitTest(player)){
player.x+=12;
}
}
if(isKeyDown('up')){
player.y-=5;
if(this.hitTest(player)){
player.y+=12;
}
}
if(isKeyDown('down')){
player.y+=5;
if(this.hitTest(player)){
player.y-=12;
}
}
if(this.hitTest(player)){
player.x -= (this.x - this.x) * .01;
player.y -= (this.y - this.y) * .01;
}
1 Like