My "Basic" ai code has a problem

Blitz3D Forums/Blitz3D Beginners Area/My "Basic" ai code has a problem

nobudgetgames(Posted 2005) [#1]
;move enimie
if Dist=5 and spotted$="True"
PointEntity terror,camera
MoveEntity terror,0 ,0 ,0.05
endif

Ok the problem with this code is that when the enmey object Begins to move towards the player, it also tilts At unwanted angles (the camera Angle) How Can i stop The Object From Tilting As it Moves?


Sledge(Posted 2005) [#2]
reset its roll?

RotateEntity terror, EntityPitch(terror), EntityYaw(terror),0



EDIT: Also, shouldn't you check if Dist is less than a certain value rather than equal?


nobudgetgames(Posted 2005) [#3]
ok Thanks


nobudgetgames(Posted 2005) [#4]
No it still tilts Im not to sure why.


WolRon(Posted 2005) [#5]
Show your new code.


Sledge(Posted 2005) [#6]
reset its pitch?


lo-tekk(Posted 2005) [#7]
Create a pivot for the camera with the same y as the enemy so that the pivot follows the cam and point the enemy to the pivot instead the camera.


-------------------------------------------
http://www.moonworx.de


nobudgetgames(Posted 2005) [#8]
Sorted it (Reset the Pitch and yaw to zero each loop)

;move enimie
If Dist<5 And spotted$="True"
PointEntity terror,camera
MoveEntity terror,0 ,0 ,0.05
EndIf

RotateEntity terror, 0, 0,0
TurnEntity terror,0,camera,0

The only problem now is i cant get the right side of the enemy to face the camera.


WolRon(Posted 2005) [#9]
The only problem now is i cant get the right side of the enemy to face the camera.
Duh. You are telling it to point at 0,0,0.

And your
TurnEntity terror,0,camera,0
bit of code is actually totally screwed up. The reason is because you are setting the entities Yaw rotation to equal the cameras HANDLE (which could be ANYTHING), not the cameras yaw rotation. In order to set it to the cameras yaw rotation, you would type it in like:
TurnEntity terror,0,EntityYaw(camera),0
.

But anyways, how your code should have looked should probably have been like so:
;move enemy
If Dist<5 And spotted=True
PointEntity terror, camera
RotateEntity terror, EntityPitch(terror), 0, 0 ;no yaw rotation nor roll rotation
MoveEntity terror,0 ,0 ,0.05
EndIf
Note that I changed your spotted variable to an integer. This is not necessary but is good programming practice since integers are much faster to use than strings.

By the way, What are the forum codes?