Camera Problem

Posted By: Omighty

Camera Problem - 03/29/10 20:06

I can't seem to get the camera behind the player. But every thing else apart from the camera position works fine. At the moment the camera is facing the side of the player instead of it being behind the player.

This is the code that I use, is there something wrong?



function camera_follow(ENTITY* chrac)
{
while(1) {
vec_set(camera.x,vector(-250,-45,45)); // camera position relative to the player
vec_rotate(camera.x ,chrac.pan); // rotate the camera position with the player
vec_add(camera.x,chrac.x); // add player position
vec_set(camera.pan,vector( chrac.pan,-10,0)); // look in player direction, slighty down
wait(1);
}
}

action player_1() // control the player
{

camera_follow(my);


VECTOR vFeet;
vec_for_min(vFeet,my); // vFeet.z = distance from player origin to lowest vertex
my.STATE = 1;
var walk_speed = 0;
var stand_speed = 0;
var run_speed = 0;

while (1)
{
stand_speed += 2*time_step;
ent_animate(me,"Stand",stand_speed,ANM_CYCLE);

// state 1: walking ////////////////////////////////////////////
if (key_cuu)
{
// rotate the entity with the arrow keys
my.pan += (key_cul-key_cur)*5*time_step;

// move the entity forward/backward with the arrow keys
var distance = (key_cuu-key_cud)*5*time_step;
c_move(me, vector(distance,0,0), NULL, GLIDE);

// animate the entity
walk_speed += 1.5*distance;
ent_animate(me,"Walk",walk_speed,ANM_CYCLE);

// adjust entity to the ground height, using a downwards trace
c_trace(my.x,vector(my.x,my.y,my.z-1000),IGNORE_ME | IGNORE_PASSABLE);
my.z = hit.z - vFeet.z; // always place player's feet on the ground


}

wait(1);
}

}


function main()
{
video_mode = 7; // 800x600 pixels
level_load ("terrain.wmb");
ent_create("MainCharacterBonesAtt.mdl", vector(-3072, 1741, -97), player_1);
wait (2);


}


Please help thanks
Posted By: Progger

Re: Camera Problem - 03/29/10 20:35

what about
camera.x=chrac.x-300*cos(chrac.pan);
camera.y=chrac.y-300*sin(chrac.pan;
camera.z=chrac.z+5;
camera.pan=chrac.pan;

I hope that helps (:
Put this in the function:

Code:
function camera_follow(ENTITY* chrac)
{
 while(1) 
 { 
  camera.x=chrac.x-300*cos(chrac.pan);
  camera.y=chrac.y-300*sin(chrac.pan;
  camera.z=chrac.z+5;
  camera.pan=chrac.pan;
  wait(1);
 }
}




WFG Progger
Posted By: Omighty

Re: Camera Problem - 03/30/10 13:03

Progger thanks for the suggestion, but it still didn't work. The camera is still facing the right side of the player. Do I have to change something to the model in the med software?
Posted By: Rei_Ayanami

Re: Camera Problem - 03/30/10 13:04

the point were the camera should look should be the origin in med for the model
Posted By: Progger

Re: Camera Problem - 03/30/10 13:23

if you watch the side try camera.pan=chrac.pan-90 or try other values there
Hope that helps but check the orgin of the model like Rei_Ayanami said (:
WFG Progger
Posted By: Omighty

Re: Camera Problem - 03/30/10 16:59

hi guy thanks for the help. I manage to fix it by changing the camera position and camera rotation
it was like this

function camera_follow(ENTITY* chrac)
{
while(1) {
vec_set(camera.x,vector(-250,-45,45)); // camera position relative to the player
vec_rotate(camera.x ,chrac.pan); // rotate the camera position with the player
vec_add(camera.x,chrac.x); // add player position
vec_set(camera.pan,vector( chrac.pan,-10,0)); // look in player direction, slighty down
wait(1);
}
}

now it looks this


void camera_follow(ENTITY* chrac)
{
while(1)
{
vec_set(camera.x,vector(-40,250,50)); // camera position relative to the player
vec_rotate(camera.x ,chrac.pan); // rotate the camera position with the player
vec_add(camera.x,chrac.x); // add player position
vec_set(camera.pan,vector( chrac.pan - 90,-10,0)); // look in player direction, slighty down
//camera.x=chrac.x-300*cos(chrac.pan);
//camera.y=chrac.y-300*sin(chrac.pan);
//camera.z=chrac.z+20;
//camera.pan=chrac.pan;

wait(1);
}

Progger i dint use your code grin. But it help me a lot thanks again.
Rei_Ayanami you were right about the origin. my player was facing the wrong way in med software.

Thanks guys GOD BLESS grin
© 2024 lite-C Forums