Mobkit - Entity API [mobkit][alpha]

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

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

by Termos » Post

Update 210110

mobkit
  • collision info is now saved on the entity as self.colinfo so it's also accessible from callbacks (for MT 5.2 and older it's always nil)
  • mobkit.get_box_displace_cols() changed return format, it now returns a 2 dimensional array
-
get_box_displace_cols returns an array of all node columns a box would enter if it were displaced by a specified vector. The following image shows the result columns as highlighted.

Image

return array format:
{
{{x=,z=}, {x=,z=}, ...}
{{x=,z=}, ...}
...
}

It's 2 dimensional because sometimes making an a few nodes long move isn't going to be possible (e.g. a steep slope), then you may only take into consideration only result[1] and be able to make a move of 1 node.

This function is intended as the basis of movement behaviors of entities of arbitrary collision box sizes (both over and under 1n).
Just iterate over the result and test the nodes within these columns to check if and how an entity can go in the specified direction.
If it turns out it has to jump/step up use get_box_intersect_cols() to get the columns needed to determine if there's enough room above to make the jump.
-
Attachments
get_box_displace_cols.png
get_box_displace_cols.png (6.79 KiB) Viewed 1314 times
Last edited by Termos on Sun Jan 10, 2021 12:16, edited 2 times in total.

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

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

by Termos » Post

double sry

u18398

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

by u18398 » Post

mobkit.get_box_displace_cols(pos,box,vec,dist)

If I understand it right, this will return collisions(intersections) of my mob with the collisionbox 'box' and currently being at position 'pos' when it moved in direction 'vec' in 'dist' nodes away ?
are there any limitations in the collisionbox size ? I guess max distance is active_block_range ?

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

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

by Termos » Post

Gundul wrote:
Sun Jan 10, 2021 16:05
If I understand it right, this will return collisions(intersections) of my mob with the collisionbox 'box' and currently being at position 'pos' when it moved in direction 'vec' in 'dist' nodes away ?
Sorry I must have been unclear.
It's cols as in columns, that is x,z coordinates. It returns the columns a box (an array of 6 values) would pass by if it moved by vec.
Given the position and how far the mob can fall/jump this gives you the range of 'y' coordinates of interest, so you have the volume of nodes to check if you want it to move in that direction.

What checks exactly those are is up to mods/games. I'll probably do a generic function to determine if the box is able to move given the geometry, but mods/games need more than that (eg. mobs might want to avoid fire or stepping in poo) so you probably need it raw.

As to the limitations, the function takes any box size but remember an extent size of a real collisionbox is limited by the engine to 1.5. The number of columns the function returns is limited to 50 (safety) but the distance you pass to the function should be up to around 2 nodes, it doesn't make much sense to do more at a time.

For a basic usage example see hq_swimto in the new version.

I probably suck at naming these things, so if anyone feels they can come up with better and more descriptive names for functions etc please let me know.

u18398

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

by u18398 » Post

ok thanks, I think I am starting to understand. That is definitely more something for my smaller mobs like piranhas or the riverfish. It gives me possible y values they could move to in the near environment. Nothing for whales or eagles :)

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

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

by Termos » Post

Err, no ;)
You get the y range elsewhere, because it's easy, you've got the box dimensions and maybe other stuff like jump height and add them up.
This function gets you x's and z's that are in the box' path because that's actually more tricky to calculate.

I'll probably have to do some example behaviors using this anyway.

u18398

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

by u18398 » Post

Termos wrote:
Sun Jan 10, 2021 19:20
Err, no ;)
You get the y range elsewhere, because it's easy, you've got the box dimensions and maybe other stuff like jump height and add them up.
This function gets you x's and z's that are in the box' path because that's actually more tricky to calculate.

I'll probably have to do some example behaviors using this anyway.
LOL me stupid XD
Theory is not my thing :D

I'll write some code to check it out :)

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

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

by Termos » Post

I just remembered the radar function you developed for whales, it used minetest.find_nodes_in_area that returns a cuboid volume of nodes which works fine in orthogonal directions, diagonal not so much.
With get_box_displace cols you can implement such a radar so that you check only relevant nodes, that is only those that are in the boxes way.

u18398

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

by u18398 » Post

Yes that was the first version of the radar. It now uses raycasts which is much faster and does not need to check hundreds of nodes. But you already know what I was planning to do :)
I will try it out and check what is better/faster, your displace_cols or my raycasts :)

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

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

by Termos » Post

Gundul wrote:
Mon Jan 11, 2021 12:04
I will try it out and check what is better/faster, your displace_cols or my raycasts :)
I expect raycast to be faster but inacurate, which is fine for whales I guess, there aren't that many obstacles underwater.
For land mobs especially those with large boxes displace_cols is a must.

User avatar
MisterE
Member
Posts: 693
Joined: Sun Feb 16, 2020 21:06
GitHub: MisterE123
IRC: MisterE
In-game: MisterE

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

by MisterE » Post

I got this error:

Code: Select all


2021-01-11 23:10:49: ERROR[Main]: ServerError: AsyncErr: ServerThread::run Lua: Runtime error from mod '??' in callback luaentity_Step(): ...netest/games/mesecraft/mods/mobkit/example_behaviors.lua:590: attempt to perform arithmetic on field 'height' (a nil value)
2021-01-11 23:10:49: ERROR[Main]: stack traceback:
2021-01-11 23:10:49: ERROR[Main]: 	...netest/games/mesecraft/mods/mobkit/example_behaviors.lua:590: in function 'func'
2021-01-11 23:10:49: ERROR[Main]: 	/app/share/minetest/games/mesecraft/mods/mobkit/init.lua:619: in function 'execute_queues'
2021-01-11 23:10:49: ERROR[Main]: 	/app/share/minetest/games/mesecraft/mods/mobkit/init.lua:844: in function </app/share/minetest/games/mesecraft/mods/mobkit/init.lua:822>


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

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

by Termos » Post

MisterE wrote:
Tue Jan 12, 2021 04:19
example_behaviors.lua:590: attempt to perform arithmetic on field 'height' (a nil value)
There's something wrong with the attack target entity, it might not be a mobkit entity or there's a problem with the definition.
Mobkit entities get the height field automaticly.

User avatar
MisterE
Member
Posts: 693
Joined: Sun Feb 16, 2020 21:06
GitHub: MisterE123
IRC: MisterE
In-game: MisterE

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

by MisterE » Post

It happened while the wolf was attacking me

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

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

by Termos » Post

Must have been a coincidence.
Some other mob must have been in combat with something elsewhere.

If you look at line 590
local height = tgtobj:is_player() and 0.35 or tgtobj:get_luaentity().height*0.6
if the target is a player the height component isn't even being retrieved.

hq_attack assumes that the target is either a player or a mobkit entity, be sure to filter entites by name.

User avatar
MisterE
Member
Posts: 693
Joined: Sun Feb 16, 2020 21:06
GitHub: MisterE123
IRC: MisterE
In-game: MisterE

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

by MisterE » Post

ok. I think a wolf may have been trying to attack a mobs_redo entity because i didnt check Thanks

u18398

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

by u18398 » Post

I was still curious what that displace_cols thing really does, so I visualized it :)

Code: Select all

function water_life.radar_fast_cols(obj,dist)
	if not dist then dist = 3 end
	local pos = obj:get_pos()
	local yaw = 0
	local box = {}
	
	if obj:is_player() then
		yaw = obj:get_look_horizontal()
		box = obj:get_properties().collisionbox
	else
		yaw = obj:get_yaw()
		box = obj:get_luaentity().collisionbox
	end
	
	local vec = minetest.yaw_to_dir(yaw)
	local crasha = mobkit.get_box_displace_cols(pos,box,vec,dist)
	
	if crasha then
		
		
		for i = 1,#crasha,1 do
			for j = 1,#crasha[i],1 do
				local cpos ={x=crasha[i][j].x, y= pos.y, z= crasha[i][j].z}
				water_life.temp_show(cpos,1)
				--local node = minetest.get_node(cpos)
			end
			
		end
	end
	
end
My misunderstanding was that this function was checking for obstacles which it does not do.

The table which is returned just gives you all the coordinates your collisionbox will have contact with
in case it keeps moving in direction vector 'vec'.
This only done in 2d, so in only one plane which is as high as the objects pos.y value.
When you use yaw as a vector 'vec', then you can see the coordinates in front of your object until 'dist'.

There are no checks if there is something, only the plain coordinates.

I hope I got this right finally. If not please correct me :)

Image

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

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

by Termos » Post

Gundul wrote:
Mon Jan 18, 2021 15:23
I was still curious what that displace_cols thing really does, so I visualized it :)
Yup, that's it. So I guess I haven't done a good job of my visualization above.
Try having the whale go like 30 degrees off the world axis and then visualize, it'll become even clearer.
Gundul wrote:
Mon Jan 18, 2021 15:23
My misunderstanding was that this function was checking for obstacles which it does not do.
No it just returns the columns because modularity, so different checks can use this function, and mods would want to check for game/mod specific nodes anyway.
Gundul wrote:
Mon Jan 18, 2021 15:23
This only done in 2d, so in only one plane which is as high as the objects pos.y value.
Yes it's 2d. A 3d version is possible, but I found that the 2d version is way more useful in typical MT application so I went with that first.

u18398

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

by u18398 » Post

Termos wrote:
Mon Jan 18, 2021 22:10
Yup, that's it. So I guess I haven't done a good job of my visualization above.
Try having the whale go like 30 degrees off the world axis and then visualize, it'll become even clearer.
No that is my fault. I always had in my mind that your function would check for walkable nodes, like you
have an other function for in mobkit. I just understood your image wrongly. It was never clear to me the function
would give me all positions, the whole way long. Now that I know what the function does your image is very clear to understand.
My function is showing the positions on the fly while the whale(or something else) is moving, That helped me
a lot :)
Termos wrote: Yes it's 2d. A 3d version is possible, but I found that the 2d version is way more useful in typical MT application so I went with that first.
If someone needs it in 3d he can call it in a loop with different pos.y values. :)

BlueTangs Rock
Member
Posts: 204
Joined: Sun Jul 10, 2016 05:00
Location: Under Le' Sea

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

by BlueTangs Rock » Post

Is it alright to play with both Mobkit (specifically with water_life and wildlife enabled) and Mobs Redo on the same world?

In the past I think I've heard that they aren't compatible with each other, but I'm not sure how true it was or how the situation is like now.
Look at that, a signiture box! To bad I have nothing to put in i-... Wait...

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

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

by Termos » Post

BlueTangs Rock wrote:
Wed Jun 16, 2021 18:23
Is it alright to play with both Mobkit (specifically with water_life and wildlife enabled) and Mobs Redo on the same world?
Mobkit and my example mods are dependecy-less, so in theory they shouldn't interfere with any game/mods combinations.

BlueTangs Rock
Member
Posts: 204
Joined: Sun Jul 10, 2016 05:00
Location: Under Le' Sea

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

by BlueTangs Rock » Post

Termos wrote:
Fri Jun 18, 2021 07:45
BlueTangs Rock wrote:
Wed Jun 16, 2021 18:23
Is it alright to play with both Mobkit (specifically with water_life and wildlife enabled) and Mobs Redo on the same world?
Mobkit and my example mods are dependecy-less, so in theory they shouldn't interfere with any game/mods combinations.
This is good to know, Thank you for responding!
Look at that, a signiture box! To bad I have nothing to put in i-... Wait...

User avatar
runs
Member
Posts: 3225
Joined: Sat Oct 27, 2018 08:32

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

by runs » Post

Some errors:

Global vars that should be local:

-This is a huge error cos 'result' is a very common name for a variable:
init.lua:343:2: setting non-standard global variable result
-This should be renamed to liquidflag instead of liq:
example_behaviors.lua:171:18: setting non-standard global variable liq
-Other:
example_behaviors.lua:154:3: setting non-standard global variable heightl
example_behaviors.lua:156:4: setting non-standard global variable heightr

Grubler
Member
Posts: 98
Joined: Wed Nov 06, 2019 03:01
In-game: Grubler

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

by Grubler » Post

Big fan of the deer and wolf. Can I ask if there is a way to make the deer eat grass and stuff?

User avatar
Eris
Member
Posts: 175
Joined: Thu Nov 19, 2020 23:12
IRC: definitelya Ovalo
In-game: Eris_still_crafts

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

by Eris » Post

Grubler wrote:
Tue Sep 14, 2021 17:17
Big fan of the deer and wolf. Can I ask if there is a way to make the deer eat grass and stuff?
I think wildlife is just an example mod for this API, I doubt there will be many new features added.
Jump in the caac

Grubler
Member
Posts: 98
Joined: Wed Nov 06, 2019 03:01
In-game: Grubler

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

by Grubler » Post

I would like to be able to do it myself if possible.

Post Reply

Who is online

Users browsing this forum: No registered users and 20 guests