ok, letīs see
what do we need to script a player-script?
- c_rotate (to rotate the player)
- c_move (to move the player)
- the WASD-keys (or other - a control for the user)
- ent_cycle (to animate our model): optional
- gravity
- a jump code
how to calculate the movement
Code:
--------------------------------------------------------------------------------
(key_w-key_s)*speed_factor*time+joy_force.y*time;
--------------------------------------------------------------------------------
if w or s is pressed calculate the speed. speed_factor can be rise if the player is to slow. the "time"-factor
make it suitable for different FPS (because the player would be slower or faster on different PCs). store the
calculated var in an temporary array (i.e. movement.x)
do the same with the sided movement (a and d)
how to rotate
do it like above to calculate the rotation (pan) of the player and store it in an array (i.e. rotation.x)
how to animate
if the movement is > 0 the player should "walk". so check the var where you have stored the calculated
movement if itīs greater than zero. if yes play the animation:
Code:
--------------------------------------------------------------------------------
if(movement.x>0)&&(!player.flag1) //if flag1 is activated the animation would not be
played.{ent_cycle("walk", player.animation);player.animation -= 8*time;player.animation %=100;}
--------------------------------------------------------------------------------
donīt forget to create an animation for standing too (if the movement == 0)
how to add gravity
at first you have to trace down (to check if the player is not on the bottom). so create an array, copy the
player position (vec_set), but substract 1000 or more quants from the array. now trace (with c_trace) down
Code:
--------------------------------------------------------------------------------
c_trace(player.x, temp,ignore_me + use_box + ignore_passable);
--------------------------------------------------------------------------------
and store the result in a var (i.e. grddist). then check if the var is greater than 1. if yes, the player isnīt on
the bottom, so he has to fall. so substract from the movement.z a value (the greater, the faster the player
fall) and multiply with time
if the player is already on the floor, set the movement.z to 0!! otherwise he would not stop to fall
how to jump
the player have to move up with an excreasing (the oposite of increasing ) value.
Code:
--------------------------------------------------------------------------------
while (jump > -1) { movement.z = 18 * time * jump; jump -= 0.09 * time;
if( grddist < 5){jump = 1;break;} wait (1); }jump=1;
--------------------------------------------------------------------------------
the player moves with an excreasing speed up. the value turn to a negative var till -1 or the bottom is
reached. then the player stop to "fall" and the var will be resetted.
to make it independend from the player-code write it in another function
how to structure a player-script
itīs really simple. at first you have to calculate the needed vars. then, if you want, the jump-code, and at
least the executing. note: we have just CALCULATED all required values. but the player wonīt move if we
donīt execute it. this can we do with c_move and c_rotate. c_move has a collision-system, so we canīt go
through walls. and so should (or can) your player code looks:
Code:
--------------------------------------------------------------------------------
action player{player=my;while(player==my){//calcutlaing movement//calculating rotation//calculating
gravity//play animation//EXECUTE!if(key_space){jump();} //if space was hit,
jump!c_rotate(player,your_angle_array,ignore_passable+glide);
//rotate!c_move(player,movement.x,nullvector,ignore_passable+glide); //move!cam_pos(); //place the camera
on itīs new position!wait(1);}}
--------------------------------------------------------------------------------
the camera
write a new function that places the camera (cam_pos() or so).
that the camera is turning around the player (in a circle!) if he rotate, you can calculate the position with
sin() and cos(). so you can calculate the camera.x-position:
Code:
--------------------------------------------------------------------------------
camera.x = player.x - offset * cos(player.pan);
--------------------------------------------------------------------------------
offset is the radius between the player and the cam. calculate the camera.y too and define the height of
the cam:Code:
--------------------------------------------------------------------------------
camera.z = player.z + cam_height;
--------------------------------------------------------------------------------
cam_height is the height-offset to the player-height and the camera-height.
but oh! the camera doesnīt look in the player-direction! change it by set the camera.pan with the
player.pan equal
note: the cam_pos will be executed every frame (in the playercode) so DONīT add in the cam_pos a while!
i hope it could help
Regards
I'd put the cam_pos(); after the c_move