(very) simple ai

Blitz3D Forums/Blitz3D Beginners Area/(very) simple ai

In my 3D world, I have a bunch of cubes, and I want a sphere to move around this world.
Basically what I want to know is how to make the sphere turn right or left randomly.
This is what i've got:
MoveEntity player,0,0,0.1

If EntityCollided(player,walltype) Then
TurnEntity player,0,3,0 
EndIf


This has the sphere always moving forward, and when it runs into a wall, it keeps turning left until it's not touching the wall anymore. But this code will make him go in 'circles' because it is only turning left, and I want to make it randomly choose to go left or right when it hits the wall. I've tried randomly choosing a number from 1 to 2, but because it is held against a wall, it chooses a number too many times and causes it to just 'jitter' in one place.
Can someone help me out?

-Thanks

Greetings Puppies,

Move the player back to it's previous position before turning so the collision doesn't keep happening.

Peace,

Jes

But if the player stops touching the wall, it will stop turning...

Greetings Puppies,

Well, when it hits the wall, set a flag to say 'You've hit a Wall, step back, sit and swivel(until rotated, then unset the flag).'

Peace,

Jes

That would work, but how do I rotate it until it reaches a 90 degree point?

I wouldn't do it that way. I'd maintain a variable that kept track of the turning direction, which would be either 0,1 or -1. If the sphere hits a wall while that variable equals zero then you know to set it to either -1 or 1 randomly; If the sphere does not hit any wall then you know to set it to 0; If the sphere hits a wall and it's already a non-zero value then you know to maintain that value. Result: The sphere will start to turn in a random direction when it collides with a wall and keep turning in that direction until it eventually moves away on a new heading.

It works now, thanks!
Like this:
        MoveEntity player,0,0,0.1
	
	TurnEntity player,0,turn,0
	
	If EntityCollided(player,walltype) Then
	
		If turn=0 Then num=Rnd(1,2)
		If num=1 Then turn=3 
		If num=2 Then turn=-3
										 
	Else
	
		turn=0	
					
	EndIf


Greetings Puppies,

Well done!

Peace,

Jes