-
Junior Member
Hit detection based on a angle.
I am making a skill game where zombies come at you. You are in a fixed position, you can only look left and right. I got everything working the way I want, the gun shoots, you lose ammo, zombies can come at you randomly, etc. the only thing I don't have working is making the zombies take damage when you shoot them. I have to some way make the zombies lose hp when you are looking at them and also holding RT. any suggestions? How have people done this before in trials evo?
-
Senior Member
Hi, yes its totally doable 
if you are using OPE for the zombies then its simpler:-
there is a really handy function inside the object info tool card called screen, screen quite simply gives the X or Y of an object in 2 dimensional screen coordinates
Screen X) left is -1, right is +1
Screen Y) up is +1, down is -1
Screen Z) if its in front its +, behind -
target each zombie with a ScreenX tool card then pass this value to a one input operator set on Abs, the Abs function turns negative numbers into positive ones, now use a generic filter to test if this value is say less than 0.1 , bare-in-mind when the zombie is close, this margin will still apply, even though the zombie is filling the screen!! so you might want to increase this number to 1 based on its distance to you. Now target the ScreenZ tool card to a zombie and pass this value to a generic filter test set to Greater than 0.
setting up the test inside your fire code
impulse from firing code->Generic filter is ScreenZ greater than 0, true impulse ->generic filter is Screen X less than 0.1 true impulse pass to HP etc.
if you are inserting this code in an impulse chain then make sure you pass the false on to the part you inserted on eg:
A->B->C , if you insert D between A and B then all D's false impulses will be passed to B, or pass it to the next zombies tests and on the last zombie pass its false onto B.
if you want to see the effects of the screen function on operation, place a dummy object and target it with a vector object info set to screen, now pick up the dummy object and move it about your TVs X/Y and observe the results.
if you are using physics to move the zombies, its much harder but still doable, but i think the easiest method is to use the above but OPE invisible objects to each zombies location and use this as the screen targets.
hope this helps.
-
Junior Member
This helps a ton! Thanks so much! I didn't even know you could get screen position that makes things easier and more reliable! Thanks a ton!