attached player doesnt move player:get_pos()

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

attached player doesnt move player:get_pos()

by MisterE » Post

So I am making a game where you have a player attached to a character entity. The entity moves, so so does the player. at least, the player's viewpoint moves with the entity, but when I query the player's position using player:get_pos() , it always returns the location at which the player was first attached to the entity.

Why is this, and how do I get around it? I need to get the position of the player, as attached to the entity. I DO need to get it from the player, I don't think I can directly get the location from the entity, since all my variables reference the player

User avatar
Krock
Developer
Posts: 4650
Joined: Thu Oct 03, 2013 07:48
GitHub: SmallJoker
Location: Switzerland
Contact:

Re: attached player doesnt move player:get_pos()

by Krock » Post

What's your Minetest version? I thought I fixed that a while ago by updating the player's absolute position every now and then using the attachment's position.
EDIT: This code requires that the player's position is correct on server-side: https://github.com/minetest/minetest/bl ... #L786-L793
EDIT2: Should be fixed at least since 5.2.0-dev: https://github.com/minetest/minetest/commit/81c2370c8
Look, I programmed a bug for you. >> Mod Search Engine << - Mods by Krock - DuckDuckGo mod search bang: !mtmod <keyword here>

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

Re: attached player doesnt move player:get_pos()

by MisterE » Post

I have mt 5.3. Maybe it didnt get fixed for some reason?

What would happen if, while the player was attached, I set the position of the player to the character entity's location in the entity's on_step?

User avatar
Krock
Developer
Posts: 4650
Joined: Thu Oct 03, 2013 07:48
GitHub: SmallJoker
Location: Switzerland
Contact:

Re: attached player doesnt move player:get_pos()

by Krock » Post

"set_pos()" for attached objects does nothing because the position is controlled by the attachment/parent.

I used the following code to confirm that "get_pos()" is working properly. Riding a cart updates the printed value (see terminal/console window).

Code: Select all

local t = 0
minetest.register_globalstep(function(dtime)
	t = t + dtime
	if t < 1 then
		return
	end
	t = t - 1

	for i, obj in ipairs(minetest.get_connected_players()) do
		print(minetest.pos_to_string(obj:get_pos()))
	end
end)
Look, I programmed a bug for you. >> Mod Search Engine << - Mods by Krock - DuckDuckGo mod search bang: !mtmod <keyword here>

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 18 guests