Page 1 of 1

New mob mod

PostPosted: Mon Jul 11, 2016 11:18
by burli
Well, I don't want to call it API, because I think API is the wrong term

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

Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
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

Re: New mob mod

PostPosted: Tue Jul 12, 2016 14:00
by Robsoie
I just watched your videos from your post on the video thread and the less i can say is that i'm very impressed.

And getting 170 creature using your movement code without any lag, that's nothing short of amazing.
Good luck in improving your excellent work.

Re: New mob mod

PostPosted: Tue Jul 12, 2016 14:58
by burli
Until now there is no real magic. I just calculate some vectors and leave the rest to the engine. It will become interesting if I have to read nodes and make decisions

I will upload the video later

Re: New mob mod

PostPosted: Wed Jul 13, 2016 23:18
by Byakuren
Are you naming your mod "mobs"?

EDIT: Also I would recommend using yaw prediction less than 1 so that the turning looks smoother.

Re: New mob mod

PostPosted: Thu Jul 14, 2016 03:13
by burli
Byakuren wrote:Are you naming your mod "mobs"?

EDIT: Also I would recommend using yaw prediction less than 1 so that the turning looks smoother.


I decided to name it s_mobs where s stands for steering, smooth or smart, whatever you prefer.

And the smoothness is limited because of the on_step call frequency

Re: New mob mod

PostPosted: Thu Jul 14, 2016 09:01
by Byakuren
burli wrote:
Byakuren wrote:Are you naming your mod "mobs"?

EDIT: Also I would recommend using yaw prediction less than 1 so that the turning looks smoother.


I decided to name it s_mobs where s stands for steering, smooth or smart, whatever you prefer.

And the smoothness is limited because of the on_step call frequency


If you use the automatic_face_movement_dir property of an entity, it will gradually change visual yaw to match its velocity. I think the scale is 0.0 for no yaw prediction and 1.0 for immediately changing yaw to the movement direction. I think it might be worth removing manual yaw sets when you change your mob direction and instead use an automatic_face_movement_dir value somewhere between 0.9 and 0.99

Re: New mob mod

PostPosted: Thu Jul 14, 2016 10:27
by burli
Doesn't work well. Can't find values for a smooth rotation. Manual rotation works better so far and doesn't cost much more CPU time

Re: New mob mod

PostPosted: Thu Jul 14, 2016 16:58
by Byakuren
Alright.

Re: New mob mod

PostPosted: Thu Jul 14, 2016 17:16
by burli
Maybe I do it wrong, but I don't think so. And if I set yaw manually I have more control

Re: New mob mod

PostPosted: Thu Jul 14, 2016 17:57
by maikerumine
I really like where you are going with this. :) Keep up the progress.

Re: New mob mod

PostPosted: Fri Jul 15, 2016 04:51
by burli
Thanks. I was able to limit the rotation speed. Now they don't spin around like crazy. And they can see the nodes around, jump upstairs or turn around in front of a wall

Works well, but still far away from finished

Re: New mob mod

PostPosted: Fri Jul 15, 2016 10:48
by burli
And I guess I have to start optimization. My routine takes more than twice the time than mobs_redo. One thing is that I do a lot of vector calculation with 3d routines, but I only need 2d vectors. So maybe I will write a 2d vector library. Than I want to optimize as much as possible.

But I think it will be impossible to get the same time like mobs_redo