Those who follow the Post your videos thread may have seen what I'm working on. I'm unhappy with the current mobs so I decided to make my own mod with a different approach. I want to implement the steering behaviours from Craig Reynolds described in this paper
I also want to move most of the code from the "API" to the mob itself because I think the behaviour depends on the mob and if the mob can not breed for example there is no need for breeding code. So I completely removed the on_step function from the "API" like in mobs_redo and moved it to the mob itself. I want to provide lots of functions to build mobs and a mob template to start with.
The code for the wanderer from the third video is not more than this
- Code: Select all
on_step = function(self, dtime)
self.acceleration = vector.new(0,0,0)
self.pos = self.object:getpos()
self.yaw = self.object:getyaw()
mobs:apply_force(self, mobs:separate(self))
mobs:apply_force(self, mobs:wander(self))
local y_velocity = self.object:getvelocity().y
self.velocity = vector.add(self.velocity, self.acceleration)
self.velocity = vector.limit(self.velocity, self.walk_velocity)
self.object:setvelocity({x = self.velocity.x, y = y_velocity, z = self.velocity.z})
self.object:setyaw(vector.yaw(self.velocity))
end,
It should be more like a construction kit with some specific configurations to make each mob individual.
I can't implement the full hierarchy of motion behaviour. This would include the calculation of each position per step. I skip this calculation and use the velocity from the previous step directly for setvelocity, which seems to work pretty well. I have tested it with over 170 sheeps and it worked without any noticeable lag, except if an new mapblock with new mobs is loaded. But I guess this is an engine issue
In the next step I will give the mobs the ability to see, hear or other "senses" and add more behaviours. My first "victim" will be the sheep