HELP ME WITH MY MOVEMENTSCRIPT / HILFE MIT MOVEMENTSCRIPT

Posted By: Schloder87

HELP ME WITH MY MOVEMENTSCRIPT / HILFE MIT MOVEMENTSCRIPT - 05/21/08 00:35

hello everyone,

i got some problems with my script.

MY PROBLEMS ARE:

1. The player should move his head, when SPACE is pressed

;

This is already working, but if i go away from SPACE, the camera should smoothly go back.

2. movement-problem: if i go around and turn, the camera should turn with the camera, but the camera has still the same position.

;

3. Zoom function: if i press mouse right, the camera should zoom into the head and the person should slowly gets transparent, that doesnt work perfectly....

;


I HOPE YOU MAY CAN HELP ME :-)

HERE IS THE SCRIPT


/////////////////////
var player_turn[3];
var player_speed[3];
var cam_bone_ang[3];
entity* spieler;

var camera_pan;
var camera_tilt;
var camera_move_to[3];
var camera_distance = 150;
var bone_ang[3];
var camera_mode = 1;
define zustand, skill51;
define ani_speed,skill90;
var steig = 0;
var camera_roll;
var tilt_bone;


action player_act
{
spieler = me;
my.polygon = on;
my.narrow = on;
my.fat = on;
my.shadow=off;
ent_bonereset(my,"bone");
my.zustand = 0;
camera.arc = 60;

while(1)
{


if(mouse_right == 1)
{
camera_mode = 2;

}
else
{
camera.arc=60;
camera_mode = 1;
}


///Animation
if((key_w || key_s) == 1)
{
ent_animate(my,"walk",my.ani_speed,ANM_CYCLE);
my.ani_speed += 4*time_step;

if(my.ani_speed > 100){my.ani_speed = 0;}
}

if(key_w == 0 && key_s == 0 && key_a == 0 && key_d == 0)
{
ent_animate(my,"idle",my.ani_speed,ANM_CYCLE);
my.ani_speed += 2*time_step;
if(my.ani_speed > 100){my.ani_speed = 0;}
}

///Camera
if(camera_mode == 1)
{

camera.pan = camera_pan;
camera_pan = bone_ang.pan;
my.transparent = off;
my.alpha = 100;
camera_tilt = bone_ang.tilt;
camera_tilt = clamp(camera_tilt,-40,30);
camera_pan = clamp(camera_pan,-30,30);
temp = fcos(camera_roll+camera_pan,-camera_distance);
vec_set(camera_move_to.x,vector(my.x + fcos(camera.pan,temp),my.y + fsin(camera.pan,temp),my.z + 40 + fsin(camera_tilt,-camera_distance)));

temp = min(1,0.3 * time_step); //changing 0.5 will change how fast the camera moves, at 1 places us at target, this value is what allows the smooth movement
camera.x += temp*(camera_move_to.x - camera.x);
camera.y += temp*(camera_move_to.y - camera.y);
camera.z += temp*(camera_move_to.z - camera.z);

vec_set(temp, my.x);
vec_sub(temp, camera.x);
vec_to_angle(camera.pan, temp);
vec_diff(temp.x,camera.x,my.x); //find the vector from the player to the camera
vec_normalize(temp.x,16); //get the magnitude of it's vector to 16 quants and store it in temp
vec_add(temp.x,camera.x); //add the vector (from player to camera) of a magnitude of 16 quants and add it to the camera's position.
}
hande_movmenent();
handle_camera_zoom();
handle_lookaround();

wait(1);
}
}

function handle_camera_zoom()
{
if(camera_mode == 2)
{

my.transparent=on;
my.alpha -= 8*time_step;
camera.tilt += mouse_force.y * 8 * time_step;
camera.pan -= mouse_force.x * 8* time_step;
if (camera.tilt >40){camera.tilt=40;}
if (camera.tilt <-40){camera.tilt=-40;}
}
}

function handle_umschauen()
{
// Kopfdrehung
if (key_space == 1){
ent_bonereset(my, "bone"); // Bestimmung des Bones
bone_ang.pan = -(pointer.x - 400) / 10;
bone_ang.tilt = -(300 - pointer.y) / 10;
bone_ang.roll = 0;
ent_bonerotate(my,"bone", bone_ang);
}

}

function hande_movmenent()
{
player_speed.x = 2.5*(key_w - key_s);
player_turn.pan = 2*(key_a - key_d);
c_move(my,player_speed,nullvector,ignore_me + ignore_passable + glide + use_box + ignore_flag2);
c_rotate(my,player_turn, nullvector);

}


Posted By: Alan

Re: HELP ME WITH MY MOVEMENTSCRIPT / HILFE MIT MOVEMENTSCRIPT - 05/23/08 06:21

Well, I might help you with your problem that the camera doesn't turn with the player. The reason why is a mathematical one. Basically we have two points, each one defined by three values, X,Y, and Z. Therefore we have:

The Player: (pX | pY | pZ)
The camera: (cX | cY | cZ)

What we have to do now is to set the cX and cY values depending on the player's PAN-angle. Now you need a bit of knowledge about trigonometry. The sinus of the pan angle equals the camera's y-distance from the player divided by the overall-distance between the camera and the player. The cosinus of the pan-angle equals the camera's x-distance from the player divided by the overall-distance between the camera and the player.

So what is this all good for? With this in mind, the only value *you* have to choose is the overall-distance between camera and player, all other variables (cX and cY) can be calculated using the sin() and cos() functions. The cZ is easy to calculate, you just equalize it with the pZ and add any value you like, depending on how high the camera should be positioned.

The following code is the practical example of what I said before. camera_distance is the overall-distance between player and camera. Camera_height is a value you may choose yourself for the height of the camera.


camera.y = player.y - camera_distance * sin(player.pan);
camera.x = player.x - camera_distance * cos(player.pan);
camera.z = player.z + camera_height;

That code positions the camera behind the player. In order to make the camera look towards the player, just use

camera.pan = player.pan;

If you want you may also adjust the camera.tilt - value.


Greetz!


Alan
Posted By: ARAS

Re: HELP ME WITH MY MOVEMENTSCRIPT / HILFE MIT MOVEMENTSCRIPT - 05/23/08 10:46

Hallo,

ich schreibe jetzt hier einmal in deutsch, da Deine Überschrift ja auch in deutsch ist.
Ich habe Dein Script jetzt einmal umgeschrieben und hoffe die Sachen jetzt so sind,
wie Du sie haben wolltest.
Hier einmal das geänderte Script.

/////////////////////
var player_turn[3];
var player_speed[3];
var cam_bone_ang[3];
entity* spieler;

var camera_pan;
var camera_tilt;
var camera_move_to[3];
var camera_distance = 150;
var bone_ang[3];
var camera_mode = 1;
define zustand, skill51;
define ani_speed,skill90;
var steig = 0;
var camera_roll;
var tilt_bone;

var bone_move = 0;
var camera_pan_old[3] = 0,0,0;

action player_act
{
spieler = me;
my.polygon = on;
my.narrow = on;
my.fat = on;
my.shadow=off;
ent_bonereset(my,"bone");
my.zustand = 0;
camera.arc = 60;
while(1)
{
Ziel_1 = bone_ang.pan;
if(mouse_right == 1)
{
camera_mode = 2;
}
else
{
camera.arc=60;
camera_mode = 1;
}
///Animation
if((key_w || key_s) == 1)
{
ent_animate(my,"walk",my.ani_speed,ANM_CYCLE);
my.ani_speed += 4*time_step;
if(my.ani_speed > 100){my.ani_speed = 0;}
}
if(key_w == 0 && key_s == 0 && key_a == 0 && key_d == 0)
{
ent_animate(my,"idle",my.ani_speed,ANM_CYCLE);
my.ani_speed += 2*time_step;
if(my.ani_speed > 100){my.ani_speed = 0;}
}
///Camera
if(camera_mode == 1)
{
if (bone_move == 1)
{
camera_pan = bone_ang.pan;
camera_pan = clamp(camera_pan,-30,30);
vec_add(camera.pan,camera_pan);
camera.pan = clamp(camera.pan,(camera_pan_old - 30),(camera_pan_old + 30));
}
else
{
camera.pan = my.pan;
}
camera_pan = bone_ang.pan;
my.transparent = off;
my.alpha = 100;
//camera_tilt = bone_ang.tilt;
camera_tilt = clamp(camera_tilt,-40,30);
camera_pan = clamp(camera_pan,-30,30);
temp = fcos(camera_roll+camera_pan,-camera_distance);
vec_set(camera_move_to.x,vector(my.x + fcos(camera.pan,temp),my.y + fsin(camera.pan,temp),my.z + 40 + fsin(camera_tilt,-camera_distance)));
temp = min(1,0.3 * time_step); //changing 0.5 will change how fast the camera moves, at 1 places us at target, this value is what allows the smooth movement
camera.x += temp*(camera_move_to.x - camera.x);
camera.y += temp*(camera_move_to.y - camera.y);
camera.z += temp*(camera_move_to.z - camera.z);
vec_set(temp, my.x);
vec_sub(temp, camera.x);
vec_to_angle(camera.pan, temp);
vec_diff(temp.x,camera.x,my.x); //find the vector from the player to the camera
vec_normalize(temp.x,16); //get the magnitude of it's vector to 16 quants and store it in temp
vec_add(temp.x,camera.x); //add the vector (from player to camera) of a magnitude of 16 quants and add it to the camera's position.
}
hande_movmenent();
handle_camera_zoom();
handle_umschauen();
wait(1);
}
}
function handle_camera_zoom()
{
if(camera_mode == 2)
{
my.transparent=on;
my.alpha -= 8*time_step;
camera.tilt += mouse_force.y * 8 * time_step;
camera.pan -= mouse_force.x * 8* time_step;
if (camera.tilt >40){camera.tilt=40;}
if (camera.tilt <-40){camera.tilt=-40;}
temp = min(1,0.1 * time_step);
camera.x += temp*(my.x - camera.x);
camera.y += temp*(my.y - camera.y);
camera.z += temp*((my.z + 30) - camera.z);
camera.pan = my.pan;
}
}


function handle_umschauen()
{
if (key_space == 1)
{
camera_mode = 3;
}
// Kopfdrehung
if (key_space == 1)
{
if (bone_move == 0)
{
camera_pan_old.pan = camera.pan;
bone_ang.pan = 0;
}

bone_move = 1;
ent_bonereset(my, "bone"); // Bestimmung des Bones
bone_ang.pan = -(pointer.x - 400) / 10;
bone_ang.pan = clamp(bone_ang.pan,-30,30);
bone_ang.tilt = -(300 - pointer.y) / 10;
bone_ang.roll = 0;
ent_bonerotate(my,"bone", bone_ang);
}
if (camera_mode != 3 && bone_move == 1)
{
ent_bonereset(my, "bone");
bone_ang.pan = 0;
bone_move = 0;
}
}

function hande_movmenent()
{
player_speed.x = 2.5*(key_w - key_s) * time_step;
player_turn.pan = 2*(key_a - key_d) * time_step;
c_move(my,player_speed,nullvector,ignore_me + ignore_passable + glide + use_box + ignore_flag2);
c_rotate(my,player_turn, nullvector);
}


Wenn´s irgendwelche Fragen dazu gibt einfach wieder melden.
Posted By: Schloder87

Re: HELP ME WITH MY MOVEMENTSCRIPT / HILFE MIT MOVEMENTSCRIPT - 05/24/08 10:47

hey, vielen dank, funktioniert fast alles wie geschmiert. nur habe ich keine pan-funktion im zoommodus und keine tiltfunktion im umschaumodus.


aber schon mal vielen dank dafür :-)
Posted By: ARAS

Re: HELP ME WITH MY MOVEMENTSCRIPT / HILFE MIT MOVEMENTSCRIPT - 05/24/08 13:35

Hi,

die pan-Funktion im Zoommodus ist schon möglich. Mit den Tasten a-d kannst Du die
steuern. Ich habe die Funktion jetzt für die Mausbewegung auch einmal eingebaut.
Hier der neue Funktionsteil:
Ändere in der Funktion "function handle_camera_zoom()" die Zeile "camera.pan -= mouse_force.x * 8* time_step;"
in "my.pan -= mouse_force.x * 8* time_step;" um.

Und mit der tilt-Funktion. Ja die habe ich einfach vergessen, sorry.
Hier die neuen Anlagenteile:
Das ganze in der Aktion "action player_act" ändern.
Die Zeilen bei denen dahinter steht, "Neue Angaben für tilt-Bewegung des Kopfes"
einfach neu einfügen.

if(camera_mode == 1)
{
if (bone_move == 1)
{
camera_pan = bone_ang.pan;
camera_tilt = bone_ang.tilt; // Neue Angaben für tilt-Bewegung des Kopfes
camera_tilt = clamp(camera_tilt,-40,30); // Neue Angaben für tilt-Bewegung des Kopfes
camera_pan = clamp(camera_pan,-30,30);
vec_add(camera.pan,camera_pan);
camera.pan = clamp(camera.pan,(camera_pan_old - 30),(camera_pan_old + 30));
}
else
{
camera_tilt = 0; // Neue Angaben für tilt-Bewegung des Kopfes
camera.pan = my.pan;
}


So, ich glaube das ist alles. Müsste so funktionieren.
© 2024 lite-C Forums