Simple Ladder Climbing

From GameStudio Wiki

Jump to: navigation, search

This is a very simple example on how to let the player climbing a ladder. Copy it into your script, assign the action ladder to your laddermodel and set the climbingspeed through skill1 on the behaviorpanel or leave the default value. This works only for a player, assigned to the player pointer. And is far not perfect, but should you an idea on how to realize something like that. (This snippet should also work with the templateplayer.)

function ladder_event()
{
	if(you)
	{
		if(you == player)
		{
			my.enable_impact = off;	//prevent the event to be triggered again and again during climbing
			
			vec_set(my.skill21,player.x);	//store the players position
			vec_set(my.skill24,player.pan);	//store its angles
			
			while(1)
			{
				proc_late();
				
				vec_set(player.x,my.skill21);	//place it at the stored position to prevent the normal movement
//				vec_set(player.pan,my.skill24);	//enable this to disable the player from turning during climbing
				
				my.skill30 = c_move(player,nullvector,vector(0,0,(key_w-key_s)*my.skill1*time_step),ignore_passable|ignore_passents|glide);	//move the player up or down
				if((key_s && my.skill30 < 0.1) || (key_w && (player.z+player.min_z) > (my.z+my.max_z+player.max_z)))	//if the ground or the end of the ladder is reached,
				{
					break;	//stop the loop
				}
				
				vec_set(my.skill21,player.x);	//stores the new position
				
				wait(1);
			}
			
			wait(-0.1);	//prevent the player from triggering the event again and again when leaving the ladder
			my.enable_impact = on;	//make the ladder again sensible for the player
		}
	}
}

//skill1: ClimpSpeed 10
action ladder()
{
	my.enable_impact = on;
	my.event = ladder_event;
	
	my.polygon = on;
	
	c_setminmax(me);
}

--Slin 04:57, 26 October 2007 (CEST)

Personal tools