## How to go about creating a custom mob engine

LC Creations
Member
Posts: 77
Joined: Mon Feb 18, 2019 02:53

### How to go about creating a custom mob engine

So, I know there are a lot of mob api's out there. But, I really want to learn and I also want to not use another person's api as much as possible. So directing me to an api is not the answer I'm looking for. I'm also not trying to get anyone to write me any code. What I am asking is how to go about making a mob engine with these key questions:

What makes a mob move?
How does a mob know where to go?
How does a mob take getting hit?
Could I use the player model as a mob?
Is the player model subject to copwright?

How do I go about making this work and what type of coding does this for copyright? Are there any good tutorials out there that may help? I do hope this question helps others. Thanks.

Walker
Member
Posts: 1078
Joined: Tue Oct 03, 2017 09:22
In-game: Walker

### Re: How to go about creating a custom mob engine

I have ABSOLUTELY no plan xD
but here are my guesses:

What makes a mob move?

Code: Select all

``````set_velocity({x=num, y=num, z=num})
add_velocity({x=num, y=num, z=num})
In comparison to using get_velocity, adding the velocity and then using set_velocity, add_velocity is supposed to avoid synchronization problems.
get_velocity() — {x=num, y=num, z=num}
set_acceleration({x=num, y=num, z=num})
get_acceleration() — {x=num, y=num, z=num}
set_rotation(rot)
rot is a vector containing euler angles (radians), also see https://en.wikipedia.org/wiki/Euler_angles
These angles describe a right-handed, extrinsic rotation about axes z, x, y (in that order).
get_rotation() — returns a rotation``````
How does a mob know where to go?

Code: Select all

``````minetest.find_path(pos1,pos2,searchdistance,max_jump,max_drop,algorithm)
- returns a table of 3d points representing a path from pos1 to pos2 or nil
- pos1: start position
- pos2: end position
- searchdistance: number of blocks to search in each direction
- max_jump: maximum height difference to consider walkable
- max_drop: maximum height difference to consider droppable
- algorithm: A*_noprefetch(default), A*, Dijkstra
RETURN: table containing path``````
How does a mob take getting hit?

Code: Select all

``````on_punch(self, puncher, time_from_last_punch, tool_capabilities, dir) — Called by the engine when somebody punches the object. Note that you probably want to handle most punches using the automatic armor group system (See #Entity Damage).
- puncher — An ObjectRef or nil.
- time_from_last_punch — Can be used to calculate damage. Can be nil.
- tool_capabilities — Capability table of used tool. Can be nil.
- dir — Unit vector in the direction of the punch. Points from the puncher to the entity, and is always defined.``````
Could I use the player model as a mob?
yes ^^

AiTechEye
Member
Posts: 775
Joined: Fri May 29, 2015 21:14
GitHub: AiTechEye
Location: ¯\_(ツ)_/¯

### Re: How to go about creating a custom mob engine

here is an explanation of my perspective:

What makes a mob move?
just add randomly velocity:

Code: Select all

``````function simple_walk(self)
if math.random(1,3) > 1 then-- stands at 1
local v = self.object:get_velocity()
-- setts its old y velocity to not change its fall
self.object:set_velocity({
x=math.random(-1,1),
y=v.y,
z=math.random(-1,1)
})
end
end``````
add this and the mob gets gravity

Code: Select all

``````on_activate=function(self, staticdata)
self.object:set_acceleration({x =0, y=-9, z =0})``````

How does a mob know where to go?
see Walker

How does a mob take getting hit?
see Walker

Could I use the player model as a mob?
of couse you can use any models, but all models arent supported with animations, .b3d is but not .obj

Is the player model subject to copwright?
way easyer if you just using it from your mod.

add depends = player_api
then

Code: Select all

``````minetest.register_entity("mod:mob",{
hp_max = 20,
collisionbox = {-0.35,-0.01,-0.35,0.35,1.8,0.35},
visual = "mesh",
mesh = "character.b3d",
textures = {"character.png"},``````

How do I go about making this work and what type of coding does this for copyright? Are there any good tutorials out there that may help? I do hope this question helps others. Thanks.

when i learned to code lua/mods for minetest i was playing around and changed code in peoples mods until i understood how it worked

so if you want i can make a simple mobmod to you that you can playaround with.

just ask me, i know how to make the most things :)

AiTechEye
Member
Posts: 775
Joined: Fri May 29, 2015 21:14
GitHub: AiTechEye
Location: ¯\_(ツ)_/¯

### Re: How to go about creating a custom mob engine

i think i spended litle too much time on it, but it has everything a mob need to work https://github.com/AiTechEye/easy_mob

### Who is online

Users browsing this forum: No registered users and 0 guests