computer ai
Blitz3D Forums/Blitz3D Beginners Area/computer ai
| ||
i was trying to make some decent oponents for a first person shooter but my ai is terrible i would like to be able to sneak up behind the opponent but if i use entity in view they see me (obviously). i also tried to make an invisible vision cone that if collided with ment they could see me but it dident work propely, there must be a simple solution please can someone tell me what it is |
| ||
The cone sounds like a good idea, why didn't it work? of course, it would need some checks in case you were in the field of vision of the enemy, but behind a wall etc... Entity-In-View would assume the enemy mesh would have 360-degree vision, so his needs combining withsome Entity-Facing checking. Erm.. Im going away to think some more... 'Ohmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm' |
| ||
I have tried using a cone as an invisible "sensor" and the problem is if the entity you are trying to detect resides entirely within the mesh of the sensor cone then meshesintersect() returns false because they are not intersecting. One possible way around this is to define your own volume in front of your AI creature and manually work out if your player is within that volume. another possible way is to detect collisions against the invisible mesh and use render tweening. this reduces the number of program cycles needed for each animation frame and will detect if your player collided with the mesh during the last cycle. both of these combined with entityInView this will cope with obscuring objects such as walls, crates etc. they still may not be the best ways of doing this :/ |
| ||
Great idea Luke! -RZ |
| ||
Hmm... what's wrong with EntityInView or EntityVisible? It doesn't seem to assume three hundred sixty degrees of vision. There is some function, I think it is EntityPickMode, that will allow an entity to obscure other entities during an EntityVisible call, so objects in the way shouldn't be a problem if you set them up with that. Try that out. |
| ||
Attach a pivot to the enemy to act as their eyes. Pointentity this pivot to the target then do an entitypick. If the pick can see your target then check the EntityYaw of the pivot for your field of view e.g. for a 90 degree field of view do If abs(entityyaw(lookpivot))<45 ;Turn toward player etc... |
| ||
tformnormal / tformvector are another way to check if something is within a field of view. Basically do this: TargetEntity = handle of entity you wish to see if it is within view. EyeEntity = handle of entity which is trying to see something ICanSeeYou=false Tformnormal Entityx(TargetEntity)-Entityx(EyeEntity),Entityy(TargetEntity)-EntityY(EyeEntity),Entityz(TargetEntity)-Entityz(EyeEntity),0,EyeEntity ;assuming that in eyeentity's space z = forwards ;SomeFactor# is a value between 0 and 1.0, which you want to set the value close to 1.0 if you want a narrow field of view (1.0=dead ahead). A value of 0.0 would make the field of view a hemispherical one. As a suggestion try a value of about 0.7 to start with. SomeFactor#=0.7 if TformedZ()>SomeFactor# then ;ie we are in the field of view....so alright to do a linepick now as they are quite slow...(there are other ways of doing it without a line pick depending on your geometry) radiusoflinepick#=0.1 ;you set this value to what you feel is appropriate Entity=linepick( Entityx(EyeEntity),EntityY(eyeentity),entityz(eyeentity),Entityx(TargetEntity)-Entityx(EyeEntity),Entityy(TargetEntity)-EntityY(EyeEntity),Entityz(TargetEntity)-Entityz(EyeEntity),radiusoflinepick#) if entity=targetentity then ICanSeeYou=true endif This way you only do the linepick if the entity is within your cone of view. I try to avoid the picking commands whereever I can as I have a slow Pc. *Edit = forgot a pair of brackets around the linepick expression. |
| ||
Jeppe did something like this some time ago: http://www.blitzbasic.com/codearcs/codearcs.php?code=871 As well as fredborg who made another version: http://www.blitzbasic.com/codearcs/codearcs.php?code=532 |
| ||
@Matty thats exactly what I was thinking of when I suggested defining a volume in front of your AI bot. Tform the players point and see if it falls within the "sensor" rect. could use a trapezoid for field of view but thats harder to code when youre just developing the basic AI :) get it working principaly, then polish it :) |