PDA

View Full Version : [AS3] Hit test and depth


linuxbox
07-08-2010, 07:40 PM
hello there. i'm new to as3 code and creating games but i have a simple game in mind that i would like to create and it involves a simple "shooter" type of game where like, the mouse on the stage is moving a pistol or bb gun and like 15 feet away are some random appearing targets and when you press the left mouse, the pistol fires a bullet and if it hits one of the targets then a sound is played and the score is added up etc etc...

much of this i understand how to do but one thing i want to simulate is depth and gravity. from the guns perspective, the targets in the background will visually look like they are several feet away (15 or so) and i don't want the bullet to just travel in a straight line. based on the velocity of the bullet i want some gravity to "pull" the bullet down some when it's fired....making the game more difficult. and i only want the "hit" to count against the target when the bullet has reached the distance in order to actually hit the target. does this make sense?

i was wondering if anyone could show some example code to demonstrate this sort of thing in AS3. visually, my plan was to have it appear as though you were standing behind the shooter maybe a foot behind them. so my gun will end up being like a translucent gun that perhaps flashes real quick

abeall
07-08-2010, 07:48 PM
Well in Flash 10 you actually have a .z property that if you increment linerally it will create the appearance of depth.

You could also use a little mathematical perspective to get the effect:

http://www.bit-101.com/tutorials/perspective.html

linuxbox
07-08-2010, 08:27 PM
abeall, that's interesting. what i was thinking about was having two layers of targets...one lower and one higher and simply instead of having the mouse move the gun, keep the gun in a fixed position except have the barrell angle itself a bit according to the x position of the mouse which would be on the target. the targets dont stay on screen but for a second or so and you would have several appearing on those two levels at once.

if the mouse was placed higher than the bottom of the upper level targets then a hit would only apply for the upper level of targets and wouldn't matter if the bullet crossed the plane of the lower level targets. it sounds quite complicated to me actually.