I need the enemies in my little asteroids game (2D) to turn around and always be pointing at you. I have no clue how to do this, so could anyone help me with this? Thanks.
AI Help
Blitz3D Forums/Blitz3D Beginners Area/AI Help It's homing missile code but without the homing.
This might be what you want...
The image is drawn pointing to the right.
For your ship substitute the rect coordinates with your ship x,y
<edit> for slightly bouncier example.
This might be what you want...
; Initialize BB to run at 800x600 Graphics 800,600 Const iNumRotations=36 ;how many rotations do we want? Dim ShipFramesImage(iNumRotations) ;Holds the rotated images ; tell BB to handle the centering of our images AutoMidHandle True ;Load the player image And point To it with "TempImage" TempImage = LoadImage("arrowr.png") ; See if the image was loaded successfully ; (the "TempImage" will be 0 if not) If TempImage = 0 Then Text 100,100,"Invalid Image!" ; tell the user it was invalid if 0 Else ; now run through the loop and rotate the image For iLoop=0 To iNumRotations ; first let's copy the original image into the current frame ShipFramesImage(iLoop)=CopyImage( TempImage) ; then rotate that frame the appropriate number of degrees RotateImage ShipFramesImage(iLoop),iLoop*360/iNumRotations Next EndIf rect_x=400 : rect_y=300 rect_xdir=4 : Rect_ydir=4 While Not KeyHit(1) ; clear the screen Cls mx=MouseX() : my=MouseY() ; If MouseHit(1) my_angle#=ATan2(rect_y-my,rect_x-mx) If my_angle<0 my_angle=my_angle+360 ; EndIf ; Line rect_x,rect_y,mx,my Rect rect_x,rect_y,10,10,1 DrawImage(ShipFramesImage(my_angle/10),mx,my) rect_x = rect_x + rect_xdir rect_y = rect_y + rect_ydir If rect_x<0 Or rect_x>GraphicsWidth() rect_xdir=-Rect_xdir If rect_y<0 Or Rect_y> GraphicsHeight() rect_ydir=-rect_ydir Flip Wend End
The image is drawn pointing to the right.
For your ship substitute the rect coordinates with your ship x,y
<edit> for slightly bouncier example.
Yep, that should work fine. Thanks!