Hit detection in 2 / 2,5D

Started by Mouth for war, Fri 21/12/2018 12:12:18

Previous topic - Next topic

Mouth for war

Hi! Sorry if I post this in the wrong place. I wasn't sure where to put this because it's not an AGS project. I would like to get some tips here regarding hit detection. I will start by showing an illustration



Now just imagine there's a guy standing there firing that gun. There's no way in freaking hell that he would hit the guy with a bullet standing like that. but everything is done in 2D so of course it will register because the bullet will collide with the character. I have done some workarounds with hidden hit detectors that doesn't cover the whole enemy etc. What is the best way in your opinion to make the shooting accurate? What I have done now is that when you fire the gun, your collision detector object that's placed at your feet also fires a bullet, so if the bullet from your gun hits the enemy + the foot object bullet hits the enemy foot/collision detector you will hurt them. It works ok but i feel there must be a better way. This is the tough part when you work in 2D and try to simulate 3D stuff. Another option I have is something you real coder's probably will shake your head at and think "NOOOOOO, I can't stand how you defile programming like this" XD


I did this for the knife slashing and it works really good. The enemies have invisible detectors and when you slash the knife, a knife hit detector is placed by the players action point and if that collides with the enemy hit register object, you hurt them. The problem was that a hit was registered even if the enemy was standing behind you and you had your back turned at him. So I did something like "If enemy Y < player Y + both of you are facing down ----> Place enemy hit detector at enemy feet" Now you can't hurt them unless you're facing each other. Because of the perspective It seems like there must be smaller detector objects in order to hit them correctly. Making the whole enemy sprite a hit target will create those weird things like in the above picture.

Maybe I should do something like this for the bullets as well? If the enemy is standing above you/further back. The hit register object will be placed somewhere at the enemies head/chest. And if it's in front of you, place it by the thighs or knees. At least you wouldn't be able to hit them like in that illustration. Maybe I'm just making things a bit complicated now. Sometimes, someone can tell you something that makes you go "Of course, so simple, why didn't I think about THAT"  I'm probably to deep in detectors now so a fresh perspective might be needed :D
mass genocide is the most exhausting activity one can engage in, next to soccer

Crimson Wizard

#1
The solution for the above is adding extra Z or "layer of depth" coordinate for every collidable object and comparing all x, y and z coordinates. In the sideways scene walking characters and objects placed on ground have their Z adjusted to the Y of their feet. Other things, like bullets, may need different logic if they are flying across the room and not along horizontal line.

This is what in AGS is known as "Baseline" (and it may be used just the same).

Mouth for war

Hmm, in Fusion you work with hotspots. so to make objects appear in front of/behind each other you set the hotspot at the bottom/feet on every object. I guess that's the same like the baseline in AGS. That's why I have the player's feet firing a bullet as well because the feet are always at the same level so a "foot bullet" colliding with the enemies feet seems right. Only problem with that is if an enemy is standing behind an obstacle that's not tall enough to be a cover (Like a fire hydrant or something). You should indeed be able to hit the enemy then but the bullet will hit the obstacle at ground level and you will not hurt the enemy. I guess I can play around some more with that z stuff :D
mass genocide is the most exhausting activity one can engage in, next to soccer

SMF spam blocked by CleanTalk