Page 1 of 1

Adapt movement speed of player

PostPosted: Fri May 17, 2013 08:17
by qznc
Looks like the API does not support to change the movement speed?

What I ultimately want is different movement speeds for the player depending on the direction. So walking backwards is slower than walking forwards. This hopefully makes hostile mobs more dangerous in my survival game. Also making the player slower if health gets low would be nice.

PostPosted: Fri May 17, 2013 11:38
by PilzAdam
The dev wiki is incomplete. Please use lua-api.txt if you cant find a function in the wiki.

PostPosted: Fri May 17, 2013 13:04
by Calinou
qznc wrote:
What I ultimately want is different movement speeds for the player depending on the direction. So walking backwards is slower than walking forwards. This hopefully makes hostile mobs more dangerous in my survival game.


Not really possible unless playing with very low latencies, since the speeds are set server-side.

qznc wrote:Also making the player slower if health gets low would be nice.


This is probably more doable.

PostPosted: Fri May 17, 2013 13:24
by qznc
I found "player.set_physics_override", which apparently can change the players walking speed.

However, I did not find a callback for player movement, direction change, button press, or something similiar.

PostPosted: Fri May 17, 2013 15:36
by rubenwardy
qznc wrote:However, I did not find a callback for player movement, direction change, button press, or something similiar.


No. This is because scripts are server side and immense lag would be caused.

Player movement

What you can do is make a global on step that records player positions, and see if it has moved from the last check.

To do this, store each player in a table with their position. In the global on step, check though each entry to see if they have moved.

Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
-- table definition
players = {
}

-- on player join
local name = -- get the players name
players[name]={}
players[name].object = player
players[name].pos = player:getpos()


Button press
currently not possible, sorry.

PostPosted: Thu May 30, 2013 19:49
by prestidigitator
rubenwardy wrote:Button press
currently not possible, sorry.

Well, while you cannot get an event when a button is pressed, you CAN poll the player's controls using the get_player_control() or get_player_control_bits() methods of a player object. This may miss presses, but it can be useful in some contexts.