Page 1 of 1

set_look_horizontal/vertical on globalstep?

Posted: Fri Mar 30, 2018 05:54
by v-rob
I have a great idea for something, but it requires the player's view to be set horizontally and vertically all the time. Moving the mouse would ruin everything, so I need a way to keep the player's view fixed. I think the only two ways to keep this consistently is to set it every globalstep or to just not move the mouse. The second idea is obviously not feasible, so I decided to try a globalstep. It works, but the player's movement is extremely jerky. This is the code I used:

Code: Select all

minetest.register_globalstep(function(dtime)
	for _, player in ipairs(minetest.get_connected_players()) do
		player:set_look_horizontal(0)
		player:set_look_vertical(0)
	end
end)
I also tried this to stop the jerking, but it didn't work.

Code: Select all

minetest.register_globalstep(function(dtime)
	for _, player in ipairs(minetest.get_connected_players()) do
		if player:get_look_horizontal() ~= 0 or player:get_look_vertical() ~= 0 then
			player:set_look_horizontal(0)
			player:set_look_vertical(0)
		end
	end
end)
So what am I missing? Is there another way to do it other than by using a globalstep? Or is there a way to fix the jerky player movement?

I've checked that API, and there doesn't seem to be a way to keep the camera from moving. Is there? Because I wouldn't have to worry about any of this then.

Re: set_look_horizontal/vertical on globalstep?

Posted: Fri Mar 30, 2018 06:43
by sofar
This will cause a packet to be sent 10+ times per second to the client, which explains the jittery movement, the client just is constantly adjusting the view. You'd rather want some way to lock the view to an entity or lock it altogether, but I don't think there are any methods in the API to do this atm.

Re: set_look_horizontal/vertical on globalstep?

Posted: Fri Mar 30, 2018 21:05
by v-rob
Hmm. This definitely presents a problem. I need a way to ensure that the player model always faces a certain direction and the movement controls always move the player a certain direction, e.g. the player model faces along the X axis and the forward control always moves the player along the X axis while still retaining the ability to sneak, jump, run, move using the other direction keys, etc. Keeping the camera facing that direction would have been a much easier solution. I think that the only way to do this is to attach the player to an entity. I can figure out how to do that, but how do I do everything else?

Re: set_look_horizontal/vertical on globalstep?

Posted: Fri Mar 30, 2018 21:23
by sofar
I'm not sure that will even help, I think the player can still move their camera.

The only method I can think of that works is how the beds mod works: attach the player, and show a transparent formspec that prevents camera movement. No idea if camera updates work, but that would be easy to try.

Re: set_look_horizontal/vertical on globalstep?

Posted: Fri Mar 30, 2018 21:50
by v-rob
That wouldn't work properly. I need the player to be able to move. The camera not moving was the important part because it made sure that the player could only move along the X and Z axes or diagonally at 45 degrees between them, and the same movement keys would always apply to the same axes. It would also ensure that the player model always faced a certain direction. So I was saying in the last post that I probably need to attach the player to an entity to achieve that, correct?

Re: set_look_horizontal/vertical on globalstep?

Posted: Sat Mar 31, 2018 00:09
by sofar
as I said before, attaching to an entity or not, the player can still move their camera. I don't think there's a way around it.

Re: set_look_horizontal/vertical on globalstep?

Posted: Sat Mar 31, 2018 02:28
by sorcerykid
I don't think there is any way to disable camera movement, outside of modifying the client itself. With formspecs, there is no way to capture keystrokes, otherwise that solution might be feasible (albeit very much a hack). The irony is it would probably only require a few lines of CPP code to accomplish this, but no mechanism is exposed through the API.

Re: set_look_horizontal/vertical on globalstep?

Posted: Sat Mar 31, 2018 06:19
by v-rob
Oh well. I suppose I'll have to find some other way to do what I want.