3D math question
Blitz3D Forums/Blitz3D Programming/3D math question
| ||
Hey guys, I'm making a AI coding game that has tanks you can program to fight each other. I know it's been done before, but I don't care. Anyway, I need to make a radar system for my tanks. The arena that the tanks battle in is completely flat and there or only two types of objects that the radar can see, other tanks, and obsticles. Both the obsticles and the tanks are going to be entitys in the game world. I need to make a radar system that will let the user set the range of the radar, the scan arc in degrees. This is only a 2D detection, does need to detect up and down. So what I'm thinking is I need to first determine if there are anything in range of the rader, if not leave the funtion. If the first check passes, I need a way to figure out if the object it sees is in the radar scan arc. This arc would be something like 90 degrees wide in front of the tank. This is where I'm kind of lost. I'm not sure how to get the angle of the object relative to the tank. I'm guessing it's some kind of point tranform trick. Anybody got any ideas? I'm sure this is pretty easy, I'm just a dumb ass with math. |
| ||
Why not just attach an 'eye' pivot to the tank and do picks rotating the eye each frame so it scans. This way it works more like a radar as you won't get the full picture every time.Rotateentity eye,0,entityyaw(tank)+(sin(counter)*viewrange),0 counter = (counter + speed) mod 360Viewrange would be 45 to give you a 90º view arc. Speed is how fast / accurate the scan is, the faster the less accurate and therefore might miss stuff as the step size will be bigger. Then just do an EntityPick from the eye pivot. |
| ||
Have a look at the DeltaYaw command. |
| ||
The simple trig solution is to use Atan2(), which will give you the angle between two 2d points. |
| ||
Concur with Big10p! Parp .... bed!!! |
| ||
Maybe this will help: http://www.blitzbasic.com/codearcs/codearcs.php?code=1552 |
| ||
This might also help: http://www.blitzbasic.com/codearcs/codearcs.php?code=871 |
| ||
;pseudocode TFormNormal entityx(othertank)-entityx(radar),0,entityz(othertank)-entityz(radar),0,radar if TFormedZ()>0.7071 then "object is in 90 degree arc" |
| ||
P.S. I think this is a great idea for a game. Sure, it's been done before, but in my opinion it's never been done very well. Colobot had nice graphics and a sensible programming language, but the single-player gameplay was flawed and there was no competitive mode. Mind Rover had nice graphics and competitive play, but the programming language(?) was freakishly weird. CRobots had horrible graphics (ASCII) and terrible UI (command line only,) but was otherwise great. Use a simple language with a great API, some nice graphics, maybe a single player mode, and you may have a winner on your hands. If you want to go further, add Internet connectivity for entering robots into tournaments and downloading other people's (compiled) code so you can test your bots against theirs. |
| ||
actually, I'm basing the language off of FPS Creators scripting language. It's super easy and very simple to implement without having to write an entire c style script parser. This is currently working in my game. You write a text file that looks like this; :radarrange=10,radarviewangle=90 :enemyseen:state=1 :enemynotseen:state=0 :state=0:rotateright :state=1:movefore basically the commands between the first set of colons is the condition and the rest is the action. So... :enemyseen,state=1:rotateright,movefore this means that if the condition "enemyseen" and "state=1" then execute anything after the second colon. It's working perfectly so far. |
| ||
I don't know if this will help or if I even understand what you are asking, but I always use TformPoint for my radar. |