mirror of
				https://github.com/luanti-org/luanti.git
				synced 2025-10-31 15:35:21 +01:00 
			
		
		
		
	Slippery nodes
Updated and improved 'slippery' factor in a new groups setting(I'd prefer to have a new property, but that'd require a new protocol, which may not be wished? Suggestions?). Modified from: Zeg9's: minetest#817
This commit is contained in:
		| @@ -464,7 +464,7 @@ void Client::step(float dtime) | ||||
| 	// Control local player (0ms)
 | ||||
| 	LocalPlayer *player = m_env.getLocalPlayer(); | ||||
| 	assert(player != NULL); | ||||
| 	player->applyControl(dtime); | ||||
| 	player->applyControl(dtime, &m_env); | ||||
| 
 | ||||
| 	// Step environment
 | ||||
| 	m_env.step(dtime); | ||||
|   | ||||
| @@ -398,7 +398,7 @@ void LocalPlayer::move(f32 dtime, Environment *env, f32 pos_max_d) | ||||
| 	move(dtime, env, pos_max_d, NULL); | ||||
| } | ||||
| 
 | ||||
| void LocalPlayer::applyControl(float dtime) | ||||
| void LocalPlayer::applyControl(float dtime, Environment *env) | ||||
| { | ||||
| 	// Clear stuff
 | ||||
| 	swimming_vertical = false; | ||||
| @@ -611,7 +611,17 @@ void LocalPlayer::applyControl(float dtime) | ||||
| 		incH = incV = movement_acceleration_default * BS * dtime; | ||||
| 
 | ||||
| 	// Accelerate to target speed with maximum increment
 | ||||
| 	accelerateHorizontal(speedH * physics_override_speed, incH * physics_override_speed); | ||||
| 	INodeDefManager *nodemgr = m_gamedef->ndef(); | ||||
| 	Map *map = &env->getMap(); | ||||
| 	v3s16 p = floatToInt(getPosition() - v3f(0,BS/2,0), BS); | ||||
| 	ContentFeatures node = nodemgr->get(map->getNodeNoEx(p)); | ||||
| 	int slippery = itemgroup_get(node.groups, "slippery"); | ||||
| 	if (slippery==0 && (node.name=="air" || itemgroup_get(node.groups, "liquid")) && !free_move && !is_climbing && !control.sneak) | ||||
| 	{ | ||||
| 		slippery = 10; | ||||
| 	} | ||||
| 
 | ||||
| 	accelerateHorizontal(speedH * physics_override_speed, incH * physics_override_speed, slippery); | ||||
| 	accelerateVertical(speedV * physics_override_speed, incV * physics_override_speed); | ||||
| } | ||||
| 
 | ||||
|   | ||||
| @@ -50,7 +50,7 @@ public: | ||||
| 	void move(f32 dtime, Environment *env, f32 pos_max_d, | ||||
| 			std::vector<CollisionInfo> *collision_info); | ||||
| 
 | ||||
| 	void applyControl(float dtime); | ||||
| 	void applyControl(float dtime, Environment *env); | ||||
| 
 | ||||
| 	v3s16 getStandingNodePos(); | ||||
| 
 | ||||
|   | ||||
| @@ -112,12 +112,19 @@ Player::~Player() | ||||
| } | ||||
| 
 | ||||
| // Horizontal acceleration (X and Z), Y direction is ignored
 | ||||
| void Player::accelerateHorizontal(v3f target_speed, f32 max_increase) | ||||
| void Player::accelerateHorizontal(v3f target_speed, f32 max_increase, int slippery) | ||||
| { | ||||
| 	if(max_increase == 0) | ||||
| 		return; | ||||
| 
 | ||||
| 	v3f d_wanted = target_speed - m_speed; | ||||
| 	if (slippery) | ||||
| 	{ | ||||
| 		if (target_speed == v3f(0)) | ||||
| 			d_wanted = -m_speed*.5/slippery; | ||||
| 		else | ||||
| 			d_wanted = target_speed*.1 - m_speed*.1; | ||||
| 	} | ||||
| 	d_wanted.Y = 0; | ||||
| 	f32 dl = d_wanted.getLength(); | ||||
| 	if(dl > max_increase) | ||||
|   | ||||
| @@ -119,7 +119,7 @@ public: | ||||
| 		m_speed = speed; | ||||
| 	} | ||||
| 
 | ||||
| 	void accelerateHorizontal(v3f target_speed, f32 max_increase); | ||||
| 	void accelerateHorizontal(v3f target_speed, f32 max_increase, int slippery); | ||||
| 	void accelerateVertical(v3f target_speed, f32 max_increase); | ||||
| 
 | ||||
| 	v3f getPosition() | ||||
|   | ||||
		Reference in New Issue
	
	Block a user