Sniper Dot - Line of sight, or something.
Jeeze, I feel like a real newbie for posting this, but i'm stumped with something.
Basically, i'm making a top down view shoot em up, and one of the weapons is to be the Sniper rifle.
This will basically place a target icon at what-ever target is directly in front of you, closest. (the idea being that pinpoint shots kill enemies instantly while misses do little damage, sort of thing.)
I'm having trouble getting the "dot" to work.
Say if an enemy is directly in front of you, I want the dot to appear on that enemy.
At the moment the dot moves about too much if you move about. (i.e appears inside the wall, misses the target, etc.)
I've tried making the player continually spawn and shoot objects (when they hit anything set dot to that object, etc) but clearly that isn't working too well.
Any ideas? I'm stumped. Go me for sounding like a real newbie, i've only been using click products since Klick and Play was first released XD.
Re: Sniper Dot - Line of sight, or something.
Use fast loops and trigonometry.
Always
Startloop "dot"
On loop "dot"
Dot is not overlapping an obstacle (or any enemies)
Add 1 to distance (distance can be a counter, or a global value, or whatever)
Set Dot's X coordinate to X of player + (Cos(angle of player)* distance
Set Dot's Y coordinate to Y of player + (Sin(angle of player)* distance
You may have to fool around with the formulas a bit, like use a - instead of a plus, or do a 360-angle if it is going the wrong way.