how to code 'Scramble' missiles
BlitzMax Forums/BlitzMax Beginners Area/how to code 'Scramble' missiles
| ||
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 |
| ||
If theres minimal obstacles, you could use an image drawn as a cone, and check for collision with the player? |
| ||
The cone image is a good idea, but i've already a lot of images collisions tests into my game.![]() |
| ||
Is there a math formulae to check if a point is inside a cone ? |
| ||
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. |
| ||
![]() a= Atan2(dx,dy) |
| ||
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 |
| ||
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... |
| ||
'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... |
| ||
Many thanks Chris, i've spent two hours to search what was wrong inside my previous code !!! |
| ||
yeah - an sometimes you're just to close to the forest to see the trees |
| ||
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? |