set_look_horizontal/vertical on globalstep?

User avatar
v-rob
Member
 
Posts: 561
Joined: Thu Mar 24, 2016 03:19
Location: Right behind you.
GitHub: v-rob

set_look_horizontal/vertical on globalstep?

by v-rob » Fri Mar 30, 2018 05:54

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.
 

sofar
Developer
 
Posts: 1766
Joined: Fri Jan 16, 2015 07:31
GitHub: sofar
IRC: sofar
In-game: sofar

Re: set_look_horizontal/vertical on globalstep?

by sofar » Fri Mar 30, 2018 06:43

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.
 

User avatar
v-rob
Member
 
Posts: 561
Joined: Thu Mar 24, 2016 03:19
Location: Right behind you.
GitHub: v-rob

Re: set_look_horizontal/vertical on globalstep?

by v-rob » Fri Mar 30, 2018 21:05

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?
 

sofar
Developer
 
Posts: 1766
Joined: Fri Jan 16, 2015 07:31
GitHub: sofar
IRC: sofar
In-game: sofar

Re: set_look_horizontal/vertical on globalstep?

by sofar » Fri Mar 30, 2018 21:23

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.
 

User avatar
v-rob
Member
 
Posts: 561
Joined: Thu Mar 24, 2016 03:19
Location: Right behind you.
GitHub: v-rob

Re: set_look_horizontal/vertical on globalstep?

by v-rob » Fri Mar 30, 2018 21:50

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?
 

sofar
Developer
 
Posts: 1766
Joined: Fri Jan 16, 2015 07:31
GitHub: sofar
IRC: sofar
In-game: sofar

Re: set_look_horizontal/vertical on globalstep?

by sofar » Sat Mar 31, 2018 00:09

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.
 

User avatar
sorcerykid
Member
 
Posts: 861
Joined: Fri Aug 26, 2016 15:36
Location: Illinois, USA
GitHub: sorcerykid
In-game: Nemo

Re: set_look_horizontal/vertical on globalstep?

by sorcerykid » Sat Mar 31, 2018 02:28

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.
 

User avatar
v-rob
Member
 
Posts: 561
Joined: Thu Mar 24, 2016 03:19
Location: Right behind you.
GitHub: v-rob

Re: set_look_horizontal/vertical on globalstep?

by v-rob » Sat Mar 31, 2018 06:19

Oh well. I suppose I'll have to find some other way to do what I want.
 


Return to Modding Discussion



Who is online

Users browsing this forum: No registered users and 4 guests