minetest_modding_book/_en/players/player_physics.md

73 lines
2.5 KiB
Markdown
Raw Normal View History

2015-01-24 11:05:38 -08:00
---
title: Player Physics
layout: default
2017-08-26 08:40:30 -07:00
root: ../../
2018-07-15 07:28:10 -07:00
idx: 4.4
2015-01-24 11:05:38 -08:00
---
2015-02-22 02:28:37 -08:00
## Introduction
2015-01-24 11:05:38 -08:00
Player physics can be modified using physics overrides. Physics overrides can set the
walking speed, jump speed and gravity constants. Physics overrides are set on a player
2017-09-02 16:49:00 -07:00
by player basis, and are multipliers. For example, a value of 2 for gravity would make
gravity twice as strong.
2015-01-24 11:05:38 -08:00
2017-09-02 16:49:00 -07:00
* [Basic Example](#basic_example)
* [Available Overrides](#available_overrides)
* [Mod Incompatibility ](#mod_incompatibility)
* [Your Turn](#your_turn)
2015-01-24 11:05:38 -08:00
2017-09-02 16:49:00 -07:00
## Basic Example
2015-01-24 11:05:38 -08:00
2017-09-02 16:49:00 -07:00
Here is an example of how to add an antigravity command, which
2015-01-24 11:05:38 -08:00
puts the caller in low G:
{% highlight lua %}
minetest.register_chatcommand("antigravity", {
func = function(name, param)
local player = minetest.get_player_by_name(name)
player:set_physics_override({
gravity = 0.1 -- set gravity to 10% of its original value
-- (0.1 * 9.81)
})
end
2015-01-24 11:05:38 -08:00
})
{% endhighlight %}
2017-09-02 16:49:00 -07:00
## Available Overrides
2015-01-24 11:05:38 -08:00
player:set_physics_override() is given a table of overrides.\\
2017-12-04 09:03:22 -08:00
According to [lua_api.txt]({{ page.root }}lua_api.html#player-only-no-op-for-other-objects),
2015-01-24 11:05:38 -08:00
these can be:
* speed: multiplier to default walking speed value (default: 1)
* jump: multiplier to default jump value (default: 1)
* gravity: multiplier to default gravity value (default: 1)
* sneak: whether player can sneak (default: true)
2017-09-02 16:49:00 -07:00
### Old Movement Behaviour
2015-01-24 11:05:38 -08:00
2017-09-02 16:49:00 -07:00
Player movement prior to the 0.4.16 release included the sneak glitch, which
allows various movement glitches, including the ability
to climb an 'elevator' made from a certain placement of nodes by sneaking
(pressing shift) and pressing space to ascend. Though the behaviour was
unintended, it has been preserved in overrides due to its use on many servers.
2015-01-24 11:05:38 -08:00
2017-09-02 16:49:00 -07:00
Two overrides are needed to fully restore old movement behaviour:
* new_move: whether the player uses new movement (default: true)
* sneak_glitch: whether the player can use 'sneak elevators' (default: false)
2018-07-15 07:28:10 -07:00
## Mod Incompatibility
2017-09-02 16:49:00 -07:00
Please be warned that mods which override the same physics value of a player tend
2015-01-24 11:05:38 -08:00
to be incompatible with each other. When setting an override, it overwrites
2017-09-02 16:49:00 -07:00
any overrides that have been set before. This means that if multiple overrides set a
player's speed, only the last one to run will be in effect.
2015-01-24 11:05:38 -08:00
2015-02-22 02:28:37 -08:00
## Your Turn
2015-01-24 11:05:38 -08:00
2017-09-02 16:49:00 -07:00
* **Sonic**: Set the speed multiplier to a high value (at least 6) when a player joins the game.
* **Super bounce**: Increase the jump value so that the player can jump 20 meters (1 meter is 1 node).
* **Space**: Make gravity decrease as the player gets higher.