how to code 'Scramble' missiles

BlitzMax Forums/BlitzMax Beginners Area/how to code 'Scramble' missiles

hub(Posted 2006) [#1]
Hi !
i want add to my game some missiles like the old classic game Scramble. Missile is launched when player is near it.

What's the better method and what is the formulae to determine that player (px, py) is inside the view zone (see picture) ?

1) linepick ?
2) cone ?
3) 'oriented' rectangle
4) classic rectangle



for info and your pseudo code have this :

type tMissile
field x
field y
field Angle
end type

Many thanks for your help


Regular K(Posted 2006) [#2]
If theres minimal obstacles, you could use an image drawn as a cone, and check for collision with the player?


hub(Posted 2006) [#3]
The cone image is a good idea, but i've already a lot of images collisions tests into my game.




hub(Posted 2006) [#4]
Is there a math formulae to check if a point is inside a cone ?


sswift(Posted 2006) [#5]
A 2D cone?

You need to find the angle one point is at (the player) relative to another point (the small end of the cone) and then detrmine if it is between angles (lookdirection-conefov/2) and (lookdirection+conefov/2).

I'm sure there's code in the code archives to find the angle of one point relative to the other. I think it involves Atan or Atan2.


RiK(Posted 2006) [#6]


a= Atan2(dx,dy)


Chris C(Posted 2006) [#7]
yep atan2 and a "cone" (flat 2d code=triangle) has my vote!

atan2 I wonder if this one command has the most uses out of all the functions of just about any language


hub(Posted 2006) [#8]
Thanks, i'm trying to transform your explanations into code. Here a code that draw some cones and try to do the job ! But not work...




Chris C(Posted 2006) [#9]
'ere try this, always remember its atan2(Y,X) not X,Y and the sign of x & y is important!

you also need an extra test to allow for "cones" that span the zero angle...




hub(Posted 2006) [#10]
Many thanks Chris, i've spent two hours to search what was wrong inside my previous code !!!


Chris C(Posted 2006) [#11]
yeah - an sometimes you're just to close to the forest to see the trees


sswift(Posted 2006) [#12]
Wouldn't you have to be far from the forest not to be able to see the individual trees? Or be unable to see the forest because you're so close all you can see is trees?