If AI Sees You
Blitz3D Forums/Blitz3D Beginners Area/If AI Sees You
| ||
I don't really know where to begin. What's a general way of making it so that when the front a model turns and sees another model, well...it sees it lol. From there I can takeover. I'm not really asking for any code, although if you prefer showing some I won't mind. I'm just curious as to how I could get a NPC to spot me when turned the right way. Thanks! |
| ||
The EntityVisible command does a linepick from the source entity in the direction it is facing (+z) and returns true if the dest entity is "pickable" and is in front of the source entity. |
| ||
...or you can use DeltaPitch/Yaw if you require adjustable field of view/simulated peripheral vision. |
| ||
"EntityVisible" and it returns 1 no matter where I am. As long as the 2 objects are near eachother, it returns 1. I want to figure it out by the way the models are FACING eachother. I'm going to try GFK's way now. Edit: It works! Thanks a bunch guys. |
| ||
Thing with using DeltaPitch/Yaw is that you gotta account for occlusion. That won't tell you if there is a wall between the characters, only if they're facing each other. You're gonna need a LinePick to check for occlusion. |
| ||
I already figured that out. I'm going to use EntityDistance with DeltaYaw. |
| ||
Something like this little snippet from my code...;can we see the player or are they standing close by? PointEntity creature\sensor_look%,player\Body% ;170 degree field of view (85+85) 45=90 degree fov If Abs(EntityYaw(creature\sensor_look%))<85 Or EntityDistance(creature\colmesh%,player\Body%)<50 If EntityPick (creature\sensor_look%,300)=player\Body% creature\aware%=True creature\sensor_look% is a pivot attached to the enemy positioned at its eyes and is used for looking around. |
| ||
Err well that's a little confusing, but I got it :) Like I said, I'm just going to compare distance and DeltaYaw. I got it all planned out ;) |
| ||
btw there are some ready to use functions in the code archives. |
| ||
Just going back to what Skidracer said about EntityVisible performing linepicks in the direction the object is facing, that isn't right at all. Consider this code which demonstrates that EntityVisible only determines whether there are any 'obscurers' between object A and object B, regardless of which way any of them are facing. Graphics3D 800,600 light = CreateLight() camera = CreateCamera() sphere = CreateSphere() cube = CreateCube() cone = CreateCone() EntityPickMode cube,2 ;this is the important bit!!! PositionEntity camera,0,15,-15 PointEntity camera,sphere PositionEntity cube,0,0,-3 ScaleEntity sphere,2,1,1 While Not KeyDown(1) a = a + 1 PositionEntity cone,Sin(a) * 6,0,Cos(a) * 6 TurnEntity sphere,0,0.2,0 UpdateWorld() RenderWorld() If EntityVisible(sphere,cone) Text 0,0,"Sphere can see cone" Else Text 0,0,"Sphere can't see cone" EndIf Flip Wend |