Smart turning
Blitz3D Forums/Blitz3D Beginners Area/Smart turning
| ||
I am making a turret for my a.i. test and I was wondering if there was a easy way to make the turret turn to face the player without pointentity,turret,player right now I have if entitydistance(turret,player) =< 25 and entitypick(turret,25)=player then pointentity turret,player fire#=fire#+1 else turnentity turret,0,1,0 endif I am trying to do a Z and X axis check but I'm a little confused can someone help me? |
| ||
Try this... Function Point_Entity(entity,Target) xt#=entityx(Target) yt#=entityy(Target) zt#=entityz(Target) xdiff# = EntityX(entity)-xt# ydiff# = EntityY(entity)-yt# zdiff# = EntityZ(entity)-zt# dist#=Sqr#((xdiff#*xdiff#)+(zdiff#*zdiff#)) pitch# = ATan2(ydiff#,dist#) yaw# = ATan2(xdiff#,-zdiff#) RotateEntity entity,pitch#,yaw#,0 End Function ..its quite useful so by disabling let say pitch# /RotateEntity entity,0,yaw#,0/ you will get only Y axis rotation towards Target or do combination you want.. |
| ||
Graphics3D 1024,768,32,2 camera = CreateCamera() light = CreateLight() TurnEntity light,45,45,0 MoveEntity camera,0,30,-30 TurnEntity camera,45,0,0 cone = CreateCone(6) RotateMesh cone,90,0,0 cube = CreateCube() pointer = CreatePivot() PositionEntity cube,0,0,10 MoveMouse GraphicsWidth()/2,GraphicsHeight()/2 Repeat mx# = MouseXSpeed() / 10.0 my# = -MouseYSpeed() / 10.0 MoveMouse GraphicsWidth()/2,GraphicsHeight()/2 TranslateEntity cube,mx,0,my PointEntity pointer,cube TurnEntity cone,0,AngleDifference(EntityYaw(cone),EntityYaw(pointer))/20,0 RenderWorld Flip Until KeyHit(1) Function AngleDifference#(angle1#,angle2#) Return ((angle2 - angle1) Mod 360 + 540) Mod 360 - 180 End Function |
| ||
Instead of pointentity you could use ...DY# = Deltayaw( Turret, PLayer ) Turnentity Turret , 0 , DY , 0 or .. Dx# = entityx( Player ) - entityx( Turret ) Dz# = entityz( Player ) - entityz( Turret ) Aligntovector Turret , Dx, 0 , Dz , 3, 1 Stevie |
| ||
I kind of like double question marks approach it gives the turret a very timesplitters feel where you can avoid it but if it actually gets to pointing at you then your dead |
| ||
is there a way for the turret to face the character without having the character point at the turret? |
| ||
As mentioned above. Remember to use the global flag for turnentity ... DY# = Deltayaw( Turret, PLayer ) Turnentity Turret , 0 , DY * .05 , 0 , 1 Stevie |
| ||
I need some more help on turning! I found that your second method works really well stevie G but my ai units won't look up! I tried this dx#=EntityX(player)-EntityX(a\entity) dy#=EntityY(player)-EntityY(a\entity) dz#=EntityZ(player)-EntityZ(a\entity) AlignToVector a\entity,dx,0,dz,3,.25 AlignToVector a\entity,0,dy,0,1,.25 but it still doesn't look up! |
| ||
dx#=EntityX(player)-EntityX(a\entity, 1) dy#=EntityY(player)-EntityY(a\entity, 1) dz#=EntityZ(player)-EntityZ(a\entity, 1) AlignToVector a\entity,dx,dy,dz,3,.25 The above should work, assuming a\entity is the turret parented to the enemy. Stevie |
| ||
what If I want a moving enemy to do the same sort of thing would that work? |
| ||
No reason why not, why don't you try it. |
| ||
I just tested it out and it works perfectly! thank you Stevie |