Animal AI - Shark movement?

Hi everyone,

this is the first time i plan to make something like this. This is a small scene of a large aquarium. In the background there should be a shark swimming around that area (later also with small fishes). I dont know how to make it swim freely but i could imagine there is a way to make it swim along a curve or let it move freely in random directions but limited inside a cube (?)

I am glad to receive any help. Thanks in advance

Make it a random sensors that sets an integer property to any in range using uniform integer. Than make each integer random motion. Make the random actuator run, for example, every 60 frames by setting it’s frequency to 60. And make the surrounding cube- if shark collides cube- state 2 which contains delay for setting back to state 1(like 100 frames) and a steering actuator that makes shark flee to the center. This is just an idea, but could be working fine!

I would have a ray or radar pulse, anything in front - eat it, or turn around and swim the other way, and a above and below ray (dont go out of water or hit bottom…

thanks adriansnetlis and BluePrintRandom, i tried out both options, but they make the shark have kinda stiff movements so that it looks abit robotic in the scene.

Im now testing a new way. In my game i dont need gravity so i just let it on 0.0 . And i will make a navmesh like this and the shark will be able to move up and down freely with the curve without falling out , i have a feeling it gonna work this way.

And i need it to move on this path endlessly (circlewise, just like some racing game AIs), does anyone have an idea how to make that?



Hi! A quick made .blend (for the fun… Not very realistic):

Thanks Monster and youle

Youle the code you made seems working very well for my purposes. thank you alot
It can swim cutely now

Thanks guys!
This saved my day.

Hi, all!
I have a question.
How about the aquarium is movable?
I create a duck home which can build in wherever grid plane.
Here is my video.
Please, help me. Thanks.

How about moving the duck (and the target) with the aquarium?

I suggest to place the targets location relative to the aquarium, which is your reference then.

Yeah, parenting should solve this! by the way, yout game looks quite cool;)

I am done with the movable object with customize the code like this :

#natural animal movement
#by :
import bge
from random import uniform
from mathutils import Vector

cont = bge.logic.getCurrentController()
own = cont.owner
radarItik = bge.logic.getCurrentScene().objects[“radarItik”]
tanahKandang = bge.logic.getCurrentScene().objects[‘tanahKandang’]
PosisiTanahKandang = tanahKandang.position

def randPos():

x = uniform(0, 0.9)
y = uniform(0, 0.9)
z = uniform(0, 0.9)

return Vector((x, y, z)) + PosisiTanahKandang

if own.getDistanceTo(radarItik) < 0.2:

own.worldPosition = randPos()

vec = radarItik.getVectTo(own)[1]

radarItik.applyMovement(vec/100, False)

radarItik.alignAxisToVect(vec, 1, 0.05)
radarItik.alignAxisToVect(Vector((0, 0, 1)), 2, 0.05)

But error happened when i add other object like this video :