Mobkit - Entity API [mobkit][alpha]

User avatar
Andrey01
Member
Posts: 2371
Joined: Wed Oct 19, 2016 15:18
GitHub: Andrey2470T
In-game: Andrey01
Location: Russia, Moscow

Re: Mobkit - Entity API [mobkit][alpha]

by Andrey01 » Post

An error causes for unknown reason after I added a code of head attachment in mobkit.actfunc:

Code: Select all

2019-12-02 20:12:27: ERROR[Main]: ServerError: AsyncErr: ServerThread::run Lua: Runtime error from mod 'zombiestrd' in callback luaentity_Step(): ...storage/emulated/0/Minetest/mods/mobkit_dev/init.lua:994: attempt to index field 'lastvelocity' (a nil value)
2019-12-02 20:12:27: ERROR[Main]: stack traceback:
2019-12-02 20:12:27: ERROR[Main]: 	...storage/emulated/0/Minetest/mods/mobkit_dev/init.lua:994: in function <...storage/emulated/0/Minetest/mods/mobkit_dev/init.lua:984>
2019-12-02 20:12:27: ERROR[Main]: 	[C]: in function 'add_entity'
2019-12-02 20:12:27: ERROR[Main]: 	...age/emulated/0/Minetest/mods/zombiestrd_dev/init.lua:234: in function '?'
2019-12-02 20:12:27: ERROR[Main]: 	...torage/emulated/0/Minetest/builtin/game/register.lua:419: in function <...torage/emulated/0/Minetest/builtin/game/register.lua:399>
2019-12-02 20:12:27: ACTION[Server]: singleplayer leaves game. List of players: 
2019-12-02 20:12:27: ACTION[Main]: Server: Shutting down
It`s strange it affects somehow 'lastvelocity' field. Here the fragments of the code:

Code: Select all

function mobkit.actfunc(self, staticdata, dtime_s)
	self.logic = self.logic or self.brainfunc
	self.physics = self.physics or mobkit.physics
	
	self.lqueue = {}
	self.hqueue = {}
	self.nearby_objects = {}
	self.nearby_players = {}
	self.pos_history = {}
	self.path_dir = 1
	self.time_total = 0
	self.water_drag = self.water_drag or 1
	local name = self.name
	local head = minetest.registered_entities[name].head
	if head then
	     if self.head then -- check if a head for the object was already attached before the game restart 
	          self.head:set_detach() -- then remove it and reset the new one with updated coords
	          self.head:remove()
	     end
	
	     local rel_pos = minetest.registered_entities[head].pos
	     local pos = self.object:get_pos()
	     local real_pos = {x = pos.x+rel_pos.x, y=pos.y+rel_pos.y, z=pos.z+rel_pos.z}
	     local head_obj = minetest.add_entity(rel_pos, head)
	     local rot = self.object:get_rotation() 
	     head_obj:set_attach(self.object, "", rel_pos, {x=deg(rot.x), y=deg(rot.y), z=deg(rot.z)})
	     self.head = head_obj
	else                              -- if a head was set before and an user deleted 'head' field after, delete that head
	      if self.head then
	            self.head:set_detach()
	            self.head:remove()
	            self.head = nil
	      end
	end

	local sdata = minetest.deserialize(staticdata)
	if sdata then 
		for k,v in pairs(sdata) do
			self[k] = v
		end
	end
	
	if self.timeout and self.timeout>0 and dtime_s > self.timeout and next(self.memory)==nil then
		self.object:remove()
	end
	
	if not self.memory then 		-- this is the initial activation
		self.memory = {} 
		
		-- texture variation
		if #self.textures > 1 then self.texture_no = random(#self.textures) end
	end
	
	-- apply texture
	if self.texture_no then
		local props = {}
		props.textures = {self.textures[self.texture_no]}
		self.object:set_properties(props)
	end

--hp
	self.max_hp = self.max_hp or 10
	self.hp = self.hp or self.max_hp
--armor
	if type(self.armor_groups) ~= 'table' then
		self.armor_groups={}
	end
	self.armor_groups.immortal = 1
	self.object:set_armor_groups(self.armor_groups)
	
	self.buoyancy = self.buoyancy or 0
	self.oxygen = self.oxygen or self.lung_capacity
	self.lastvelocity = {x=0,y=0,z=0}
	self.sensefunc=sensors()
end

function mobkit.stepfunc(self,dtime)	-- not intended to be modified
	self.dtime = min(dtime,0.2)
	self.height = mobkit.get_box_height(self)
	
--  physics comes first
--	self.object:set_acceleration({x=0,y=mobkit.gravity,z=0})
	local vel = self.object:get_velocity()
	
--	if self.lastvelocity.y == vel.y then
--	if abs(self.lastvelocity.y-vel.y)<0.001 then
	if self.lastvelocity.y==0 and vel.y==0 then     -- ERROR! No 'lastvelocity' available in 'self'
		self.isonground = true
	else
		self.isonground = false
	end
	
	self:physics()

	if self.logic then
		if self.view_range then self:sensefunc() end
		self:logic()
		execute_queues(self)
	end
	
	self.lastvelocity = self.object:get_velocity()
	self.time_total=self.time_total+self.dtime
end

Gundul
Member
Posts: 845
Joined: Thu Aug 27, 2015 10:55
GitHub: berengma
IRC: Gundul
Location: Europe/Asia

Re: Mobkit - Entity API [mobkit][alpha]

by Gundul » Post

Termos wrote: The way i see it, these are two separate things

The first is environment damage.
Isinliquid checks only single node at a single point, while even the smallest colbox can intersect with up to 8 nodes. This his where mobkit.get_nodes_in_area comes in handy. For examples see zombies and wildlife animals, they have lava damage enabled.
that is exactly what I want to avoid. Checking areas. minetest.find_nodes_in_area would do that pretty
precisely.
I think if there is no disadvantage in giving the info of what the liquid is made of, instead of just true or false,
it would be better to give it and let the modder decide what to do with it.
Termos wrote: The second is avoiding certain nodes
Isinliquid is not very good for this, because by the time you get the info they're already there.
That is how it would work in real life. A shark enters a river from the sea. He wouldn't notice in advance.
Only if water is getting more and more different he will know that he must return where he came from.
My servers: Jungle, Lilly in the valley, ZombieTest

Termos
Member
Posts: 310
Joined: Sun Dec 16, 2018 12:50

Re: Mobkit - Entity API [mobkit][alpha]

by Termos » Post

Andrey01 wrote:An error causes for unknown reason after I added a code of head attachment in mobkit.actfunc:
Do not modify mobkit if you're ever going to distribute your stuff for use with MT, or you're breaking your own or someone else's mods, depending on which one gets loaded first. It's a shared API.

You should redownload the original and try again.
If you need to add anything to activation do something like:

Code: Select all

on_activate = function(self,sdata,dtime_s)
	-- yourstuffhere
	mobkit.actfunc(self,sdata,dtime_s)
end,

User avatar
Andrey01
Member
Posts: 2371
Joined: Wed Oct 19, 2016 15:18
GitHub: Andrey2470T
In-game: Andrey01
Location: Russia, Moscow

Re: Mobkit - Entity API [mobkit][alpha]

by Andrey01 » Post

Termos wrote:
Andrey01 wrote:An error causes for unknown reason after I added a code of head attachment in mobkit.actfunc:
Do not modify mobkit if you're ever going to distribute your stuff for use with MT, or you're breaking your own or someone else's mods, depending on which one gets loaded first. It's a shared API.

You should redownload the original and try again.
If you need to add anything to activation do something like:

Code: Select all

on_activate = function(self,sdata,dtime_s)
	-- yourstuffhere
	mobkit.actfunc(self,sdata,dtime_s)
end,
Um, I would like to add these changes in your library, not separately, then would make a PR to be merged if you approved it. And a request: could you please find out based on my code why it crashes?

Termos
Member
Posts: 310
Joined: Sun Dec 16, 2018 12:50

Re: Mobkit - Entity API [mobkit][alpha]

by Termos » Post

Andrey01 wrote: Um, I would like to add these changes in your library, not separately, then would make a PR to be merged if you approved it. And a request: could you please find out based on my code why it crashes
Ah ok then, it's fine, just give me some time to check it out and consider.

Normally I'm against adding specific features, MC based in particular, but this one seems harmless and kinda cool.
Gundul wrote:That is how it would work in real life. A shark enters a river from the sea. He wouldn't notice in advance.
Only if water is getting more and more different he will know that he must return where he came from.
Except in real life there's no sharp boundary between sea and fresh water, anyway, I'm considering, if it turns out to make no impact then I'll probably add it.

Termos
Member
Posts: 310
Joined: Sun Dec 16, 2018 12:50

Re: Mobkit - Entity API [mobkit][alpha]

by Termos » Post

Andrey01 wrote:could you please find out based on my code why it crashes?
Haven't found anything in the code that could produce such an error, probably the cause is elsewhere, entity definition perhaps?
This problem could arise if an entity had on_step=mobkit.stepfunc, but on_activate wasn't defined properly.

We're gonna have to simplify that code a lot.
- the head should be the simplest entity def possible, having only necessary properties (model,texture etc), static_save set to false and not be hooked up to mobkit.
- all relevant info should be saved on the torso entity (mobkit enabled)

maybe something like:
head_definition={
entity=,
offset=,
max_horizontal_angle=,
max_down_angle=,
max_up_angle=,
}

User avatar
Extex
Member
Posts: 184
Joined: Wed Mar 14, 2018 23:14
GitHub: Extex101
In-game: Extex

Re: Mobkit - Entity API [mobkit][alpha]

by Extex » Post

You could do it via bone rotation, instead of using separate entities
Player of PK, RIP. Creator of the light_tool and motorbike mods. Working on another mod which should be coming soon!

User avatar
runs
Member
Posts: 1562
Joined: Sat Oct 27, 2018 08:32
GitHub: runsy

Re: Mobkit - Entity API [mobkit][alpha]

by runs » Post

Extex wrote:You could do it via bone rotation, instead of using separate entities
Exactly, why separated entities are needed?
Day 42 of the quarantine

User avatar
Lone_Wolf
Member
Posts: 2328
Joined: Sun Apr 09, 2017 05:50
GitHub: LoneWolfHT
IRC: Lone_Wolf or LoneWolfHT
In-game: Lone_Wolf
Location: Not there, THERE!

Re: Mobkit - Entity API [mobkit][alpha]

by Lone_Wolf » Post

Extex wrote:You could do it via bone rotation, instead of using separate entities
IIRC bone rotation messes up animations. So that would probably be more trouble than it's worth

User avatar
Lone_Wolf
Member
Posts: 2328
Joined: Sun Apr 09, 2017 05:50
GitHub: LoneWolfHT
IRC: Lone_Wolf or LoneWolfHT
In-game: Lone_Wolf
Location: Not there, THERE!

Re: Mobkit - Entity API [mobkit][alpha]

by Lone_Wolf » Post

Was testing a mob that was set to follow me around and I noticed that almost every time it tried to jump over a bush it would get stuck in a loop. I have stepheight set to 0.6 JIC, and my collisionbox isn't larger than the size of a single node. I can provide the code if needed
Image

Termos
Member
Posts: 310
Joined: Sun Dec 16, 2018 12:50

Re: Mobkit - Entity API [mobkit][alpha]

by Termos » Post

Extex wrote:You could do it via bone rotation, instead of using separate entities
I don't know of a way of doing this without using separate entities, can you elaborate?
Lone_Wolf wrote:Was testing a mob that was set to follow me around and I noticed that almost every time it tried to jump over a bush it would get stuck in a loop.
They're programmed not to fall down farther than they can jump back up.
However, there's an oddity in that clip, it looks like one corner of the bush is missing, so it shouldn't have a problem getting down, yet it walks over the empty space like it was solid.
Do you have invisible solid nodes, or maybe the collisionbox isn't symmetrical, and hangs on the neighbor node preventing it from falling down?

User avatar
ElCeejo
Member
Posts: 66
Joined: Thu Feb 28, 2019 23:29
In-game: ElCeejo
Location: The darkest corner in your house

Re: Mobkit - Entity API [mobkit][alpha]

by ElCeejo » Post

Termos wrote:
Extex wrote:You could do it via bone rotation, instead of using separate entities
I don't know of a way of doing this without using separate entities, can you elaborate?
Minetest allows you to rotate specific bones in a rigged model through code. For example, let's say you have a bone that controls the left leg of a model called "LeftLeg", and you wanted to rotate it 90 degrees on the X axis through code, You could do:

Code: Select all

self.object:set_bone_position("LeftLeg",{x=0,y=0,z=0},{x=90,y=0,z=0})
The problem, as Lone Wolf mentioned, is that using this completely messes up animations. It's possible to use it to animate entities and the player if you know what to do but nobody has done this with entities and it probably won't happen anytime soon.

User avatar
Andrey01
Member
Posts: 2371
Joined: Wed Oct 19, 2016 15:18
GitHub: Andrey2470T
In-game: Andrey01
Location: Russia, Moscow

Re: Mobkit - Entity API [mobkit][alpha]

by Andrey01 » Post

Termos wrote:
Andrey01 wrote:could you please find out based on my code why it crashes?
We're gonna have to simplify that code a lot.
- the head should be the simplest entity def possible, having only necessary properties (model,texture etc), static_save set to false and not be hooked up to mobkit.
- all relevant info should be saved on the torso entity (mobkit enabled)

maybe something like:
head_definition={
entity=,
offset=,
max_horizontal_angle=,
max_down_angle=,
max_up_angle=,
}
What do you mean 'and not be hooked up to mobkit?'. Why? Is that needed to be separate from the main API?

Also, may anyone explain what 'stepheight' field is?

User avatar
Lone_Wolf
Member
Posts: 2328
Joined: Sun Apr 09, 2017 05:50
GitHub: LoneWolfHT
IRC: Lone_Wolf or LoneWolfHT
In-game: Lone_Wolf
Location: Not there, THERE!

Re: Mobkit - Entity API [mobkit][alpha]

by Lone_Wolf » Post

Termos wrote:They're programmed not to fall down farther than they can jump back up.
However, there's an oddity in that clip, it looks like one corner of the bush is missing, so it shouldn't have a problem getting down, yet it walks over the empty space like it was solid.
Do you have invisible solid nodes, or maybe the collisionbox isn't symmetrical, and hangs on the neighbor node preventing it from falling down?
My collisionbox:
collisionbox = {-0.5, -0.3, -0.5, 0.5, 0.5, 0.5},

User avatar
Lone_Wolf
Member
Posts: 2328
Joined: Sun Apr 09, 2017 05:50
GitHub: LoneWolfHT
IRC: Lone_Wolf or LoneWolfHT
In-game: Lone_Wolf
Location: Not there, THERE!

Re: Mobkit - Entity API [mobkit][alpha]

by Lone_Wolf » Post

Andrey01 wrote:Also, may anyone explain what 'stepheight' field is?
If an entity/player moves into the side of a block it/they will 'slide' up onto the top of it without needing to jump. Players have a stepheight of half a node. Which is what allows them to go up stairs/slabs without jumping

User avatar
Lone_Wolf
Member
Posts: 2328
Joined: Sun Apr 09, 2017 05:50
GitHub: LoneWolfHT
IRC: Lone_Wolf or LoneWolfHT
In-game: Lone_Wolf
Location: Not there, THERE!

Re: Mobkit - Entity API [mobkit][alpha]

by Lone_Wolf » Post

Termos wrote:They're programmed not to fall down farther than they can jump back up.
This spider has a jump height of 5 yet it won't jump down. It just goes in circles
Image

User avatar
Extex
Member
Posts: 184
Joined: Wed Mar 14, 2018 23:14
GitHub: Extex101
In-game: Extex

Re: Mobkit - Entity API [mobkit][alpha]

by Extex » Post

Termos wrote:
Extex wrote:You could do it via bone rotation, instead of using separate entities
I don't know of a way of doing this without using separate entities, can you elaborate?
Use object:set_bone_position.

Code: Select all

set_bone_position(bone = "Name of bone", position = {x=0,y=0,z=0}, rotation = {x=0,y=0,z=0})
Player of PK, RIP. Creator of the light_tool and motorbike mods. Working on another mod which should be coming soon!

Termos
Member
Posts: 310
Joined: Sun Dec 16, 2018 12:50

Re: Mobkit - Entity API [mobkit][alpha]

by Termos » Post

Andrey01 wrote: What do you mean 'and not be hooked up to mobkit?'. Why? Is that needed to be separate from the main API?
The head is just an attachment, not an independent entity/mob, there are no reasons for it to have separate logic, physics, awareness, function queues etc. All that would be just waste of cpu cycles.
The torso and the head make one logical whole, only one of them needs to govern it all, and it makes way more sense for the torso to be the one.

Termos
Member
Posts: 310
Joined: Sun Dec 16, 2018 12:50

Re: Mobkit - Entity API [mobkit][alpha]

by Termos » Post

Lone_Wolf wrote: My collisionbox:
collisionbox = {-0.5, -0.3, -0.5, 0.5, 0.5, 0.5},
This box is a hair wider than a node, there's no way it can fit in a 1 node gap.
Also movement is not exact, so even slightly smaller boxes would usually hang on neighboring nodes.
Lone_Wolf wrote:This spider has a jump height of 5 yet it won't jump down.
If this is the case, that may be my bad, i have to do some testing.
Meanwhile, if you downsized the box to some -0.4,0.4 I'm sure it could manage that particular bush.

Termos
Member
Posts: 310
Joined: Sun Dec 16, 2018 12:50

Re: Mobkit - Entity API [mobkit][alpha]

by Termos » Post

Update 191205

changes:
  • fixed is_neighbor_node_reachable failing check when extreme jump_height (Lone Wolf)
  • self.isinliquid now holds liquid node name or nil as opposed to true/false (Gundul)

User avatar
Lone_Wolf
Member
Posts: 2328
Joined: Sun Apr 09, 2017 05:50
GitHub: LoneWolfHT
IRC: Lone_Wolf or LoneWolfHT
In-game: Lone_Wolf
Location: Not there, THERE!

Re: Mobkit - Entity API [mobkit][alpha]

by Lone_Wolf » Post

Thanks! Works great now

Are you planning on making them jump across gaps like this? Maybe using jump_height to determine how large of a gap they can jump across
Image

Termos
Member
Posts: 310
Joined: Sun Dec 16, 2018 12:50

Re: Mobkit - Entity API [mobkit][alpha]

by Termos » Post

Lone_Wolf wrote:Are you planning on making them jump across gaps like this? Maybe using jump_height to determine how large of a gap they can jump across
Yes I am.
However with 5m jump height your spider would be able to leap over 20m+ gaps, and that's a lotta nodes to check.

User avatar
Lone_Wolf
Member
Posts: 2328
Joined: Sun Apr 09, 2017 05:50
GitHub: LoneWolfHT
IRC: Lone_Wolf or LoneWolfHT
In-game: Lone_Wolf
Location: Not there, THERE!

Re: Mobkit - Entity API [mobkit][alpha]

by Lone_Wolf » Post

Termos wrote:
Lone_Wolf wrote:Are you planning on making them jump across gaps like this? Maybe using jump_height to determine how large of a gap they can jump across
Yes I am.
However with 5m jump height your spider would be able to leap over 20m+ gaps, and that's a lotta nodes to check.
Instead of 20 node gaps you could do 5 node gaps instead. Might make more sense to modders too

User avatar
Andrey01
Member
Posts: 2371
Joined: Wed Oct 19, 2016 15:18
GitHub: Andrey2470T
In-game: Andrey01
Location: Russia, Moscow

Re: Mobkit - Entity API [mobkit][alpha]

by Andrey01 » Post

Lone_Wolf wrote:Thanks! Works great now

Are you planning on making them jump across gaps like this? Maybe using jump_height to determine how large of a gap they can jump across
Image
Also, it would be nice if spiders could climb up walls. I consider also turn them to 90 ° through X dimension to make them to make a realistic look of the climbing, not like as in MC.
Termos wrote:
Andrey01 wrote: What do you mean 'and not be hooked up to mobkit?'. Why? Is that needed to be separate from the main API?
The head is just an attachment, not an independent entity/mob, there are no reasons for it to have separate logic, physics, awareness, function queues etc. All that would be just waste of cpu cycles.
The torso and the head make one logical whole, only one of them needs to govern it all, and it makes way more sense for the torso to be the one.
Ok, I`ll erase then the redudant properties.
Lone_Wolf wrote:
Andrey01 wrote:Also, may anyone explain what 'stepheight' field is?
If an entity/player moves into the side of a block it/they will 'slide' up onto the top of it without needing to jump. Players have a stepheight of half a node. Which is what allows them to go up stairs/slabs without jumping
Ah, I`ve understood, thanks.

Termos
Member
Posts: 310
Joined: Sun Dec 16, 2018 12:50

Re: Mobkit - Entity API [mobkit][alpha]

by Termos » Post

Lone_Wolf wrote: Instead of 20 node gaps you could do 5 node gaps instead. Might make more sense to modders too
For starters I'd be happy with around two. There's the problem of finding the shortest jump across, because it would look stupid if they jumped a narrow crack at a sharp angle, with 5m that still would be an insane volume of nodes to check.
Andrey01 wrote: Also, it would be nice if spiders could climb up walls. I consider also turn them to 90 ° through X dimension to make them to make a realistic look of the climbing, not like as in MC.
Been thinking about that, kinda tricky because on vertical surfaces roll takes the role of yaw, and during transitions between flat and vertical they play both roles in part, but that's definitely doable.

Post Reply

Who is online

Users browsing this forum: Google [Bot], MusaFuchs and 6 guests