Adapt movement speed of player

qznc
Member
 
Posts: 55
Joined: Tue Jul 03, 2012 09:02

Adapt movement speed of player

by qznc » Fri May 17, 2013 08:17

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.
Last edited by qznc on Fri May 17, 2013 08:29, edited 1 time in total.
 

User avatar
PilzAdam
Member
 
Posts: 4026
Joined: Fri Jul 20, 2012 16:19
GitHub: PilzAdam
IRC: PilzAdam

by PilzAdam » Fri May 17, 2013 11:38

The dev wiki is incomplete. Please use lua-api.txt if you cant find a function in the wiki.
 

User avatar
Calinou
Member
 
Posts: 3124
Joined: Mon Aug 01, 2011 14:26
GitHub: Calinou
IRC: Calinou
In-game: Calinou

by Calinou » Fri May 17, 2013 13:04

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.
 

qznc
Member
 
Posts: 55
Joined: Tue Jul 03, 2012 09:02

by qznc » Fri May 17, 2013 13:24

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.
 

User avatar
rubenwardy
Member
 
Posts: 4500
Joined: Tue Jun 12, 2012 18:11
GitHub: rubenwardy
IRC: rubenwardy
In-game: rubenwardy

by rubenwardy » Fri May 17, 2013 15:36

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.
Last edited by rubenwardy on Fri May 17, 2013 15:40, edited 1 time in total.
 

prestidigitator
Member
 
Posts: 632
Joined: Thu Feb 21, 2013 23:54

by prestidigitator » Thu May 30, 2013 19:49

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.
Last edited by prestidigitator on Thu May 30, 2013 19:49, edited 1 time in total.
 


Return to WIP Mods

Who is online

Users browsing this forum: No registered users and 18 guests

cron