Very Basic Playermovement

From GameStudio Wiki

Jump to: navigation, search

This is an example for first person playermovement. It is just the movement without animations or anything else and so may can not be directly used for your project. But should give you an idea on how to handle the basics and is already good enough for simple testing (I tested the ladder climbing script with this player).

var key_forwards = 17;	//17 = w-key
var key_backwards = 31;	//31 = s-key
var key_left = 30;		//30 = a-key
var key_right = 32;		//32 = d-key

//skill1: MovementSpeed 10
//skill2: TurningSpeed 10
//skill3: Health 100
//skill4: CameraTiltLimit 70
//skill5: CameraEyeOffset 15
action player_act()
{
	player = me;	//set the player pointer
	camera.genius = me;
	
	while(my.skill3)
	{
		//get the keyboardinput
		my.skill21 = (key_pressed(key_forwards)-key_pressed(key_backwards))*my.skill1*time_step;
		my.skill22 = (key_pressed(key_left)-key_pressed(key_right))*my.skill1*time_step;
		
		//add advanced gravity here if needed
		
		//get the mousemovement
		my.skill24 = -mouse_force.x*my.skill2*time_step;
		my.skill25 = mouse_force.y*my.skill2*time_step;
		
		//add animations here if needed
		
		//turn and move the player
		c_rotate(me,vector(my.skill24,0,0),glide|ignore_passable|ignore_passents);
		c_move(me,my.skill21,vector(0,0,-2*time_step),glide|ignore_passable|ignore_passents);	//the second vector is used for a very simple gravity
		
		//turn and move the camera
		camera.tilt += my.skill25;
		camera.tilt = clamp(camera.tilt,-my.skill4,my.skill4);	//limit the cameras tilt
		camera.pan = my.pan;
		vec_set(camera.x,my.x);
		camera.z += my.skill5;	//add the eye offset
		
		wait(1);
	}
	
	//add a die animation here if needed
}

--Slin 03:52, 31 October 2007 (CET)

Personal tools