Posted By: Neurosys
Third Person Camera Movement WORKS GREAT but SCREEN FLICKERS! - 08/09/08 00:57
ok.. this whole app works fine. menus, panels, world setup..eveything... in startworld() we hide the PANELS since we are done with the main menu at that point.
We also do this in startworld():
That lines up the camera PERFECTLY behind the player in a third person cam type arrangement (above and behind). Now the thing is in the AUM61 code I got the vec_set thing from the player action enters a while(1) wait(1) of course and handles his movement and gravity. again.. works like a dream.. however.. when we place those 3 magic vec_??? lines from startworld():
which should (AND DO) keep the camera at its perfect 3rd person cam alignment. Thing is when I do this in the player action (or even the main loop instead) or anywhere that updates it constantly i get grey(my sky.tga color actually) flickering... so I figure the camera is going apeshit and I hit F11... bingo.. the cam is flickering thru two or more x,y,z positions and I realize the camera is being set to the vector (1 position move) rotated to match up with pan (2 moves) and added to player vector (3 moves) so I do what anyone would do and make a tempvar and do all the calcs on it behind the scenes then once I got the resulting vector copying it straight to camera vector with vec_set(camera.x,tempvar.x) well.. it works... but it still flickers!!! grr!! which is really wierd cuz in that scenario is like "wtf else is moving the cam then?" anywho.. here is the whole code and I'll totally sex0r anyone who can figure it out.
Thanks In Advance,
Neurosys
We also do this in startworld():
Code:
while(player == NULL) { wait(1); } player.x = 570; player.y = -1996; player.z = 330; player.pan = 323; vec_set(camera.x,vector(-180,0,50)); vec_rotate(camera.x,player.pan); vec_add(camera.x,player.x); camera.pan = player.pan; camera.tilt = -15;
That lines up the camera PERFECTLY behind the player in a third person cam type arrangement (above and behind). Now the thing is in the AUM61 code I got the vec_set thing from the player action enters a while(1) wait(1) of course and handles his movement and gravity. again.. works like a dream.. however.. when we place those 3 magic vec_??? lines from startworld():
Code:
vec_set(camera.x,vector(-180,0,50)); vec_rotate(camera.x,player.pan); vec_add(camera.x,player.x);
which should (AND DO) keep the camera at its perfect 3rd person cam alignment. Thing is when I do this in the player action (or even the main loop instead) or anywhere that updates it constantly i get grey(my sky.tga color actually) flickering... so I figure the camera is going apeshit and I hit F11... bingo.. the cam is flickering thru two or more x,y,z positions and I realize the camera is being set to the vector (1 position move) rotated to match up with pan (2 moves) and added to player vector (3 moves) so I do what anyone would do and make a tempvar and do all the calcs on it behind the scenes then once I got the resulting vector copying it straight to camera vector with vec_set(camera.x,tempvar.x) well.. it works... but it still flickers!!! grr!! which is really wierd cuz in that scenario is like "wtf else is moving the cam then?" anywho.. here is the whole code and I'll totally sex0r anyone who can figure it out.
Code:
//include <default.fx>; //include <mtlFX.wdl>; //include <default.fx>; //include <mtlFX.wdl>; #include <acknex.h> #include <default.c> #include "mtlFX.c" #define PRAGMA_PATH "%EXE_DIR%\code"; #define PRAGMA_PATH "images"; #define PRAGMA_PATH "terrains"; #define PRAGMA_PATH "levels"; #define PRAGMA_PATH "models"; //////////////////////////////////////////////////////////////////// #define xmax 1024 #define ymax 768 #define fscreen 1 BMAP* nneglogo = "nnegamingLOGO.bmp"; BMAP* dhlogo = "dementia_hillsLOGO.bmp"; BMAP* dhmenustart = "dhmenustart.bmp"; BMAP* dhmenustartover = "dhmenustart_over.bmp"; BMAP* mcursor = "brokenarrow.pcx"; ENTITY* skycube; PANEL* splash1 = { pos_x=0; pos_y=0; layer=2; bmap = nneglogo; flags = VISIBLE; } PANEL* splash2 = { pos_x=0; pos_y=0; layer=1; bmap = dhlogo; flags = VISIBLE; } PANEL* mainmenu = { pos_x=0; pos_y=350; layer=3; button(0,0,dhmenustart,dhmenustart,dhmenustartover,startworld,NULL,NULL); flags = OVERLAY; } function startworld(){ toggle(mainmenu,VISIBLE); toggle(splash1,VISIBLE); toggle(splash2,VISIBLE); //Start Loading Shit camera.arc = 30; //Zoom Factor while(player == NULL) { wait(1); } player.x = 570; player.y = -1996; player.z = 330; player.pan = 323; vec_set(camera.x,vector(-180,0,50)); vec_rotate(camera.x,player.pan); vec_add(camera.x,player.x); camera.pan = player.pan; camera.tilt = -15; } action players_code() { var anim_percentage; // animation percentage VECTOR movement_speed; // player's movement speed var distance_to_ground; // the distance between player's origin and the ground VECTOR temp; player = my; // I'm the player while (1) { //THIS PART CAUSE FLICKERING WHY????!!! vec_set(camera.x,vector(-180,0,50)); vec_rotate(camera.x,player.pan); vec_add(camera.x,player.x); camera.pan = player.pan; camera.tilt = -15; //THAT^ PART CAUSE FLICKERING WHY????!!! my.pan += 6 * (key_a - key_d) * time_step; // rotate the player using the "A" and "D" keys vec_set (temp.x, my.x); // copy player's position to temp temp.z -= 5000; // set temp.z 5000 quants below player's origin distance_to_ground = c_trace (my.x, temp.x, IGNORE_ME | USE_BOX); movement_speed.x = 10 * (key_w - key_s) * time_step; // move the player using "W" and "S" movement_speed.y = 0; // don't move sideways movement_speed.z = - (distance_to_ground - 17); // 17 = experimental value movement_speed.z = maxv(-35 * time_step, movement_speed.z); // 35 = falling speed c_move (my, movement_speed.x, nullvector, GLIDE); // move the player if ((key_w == OFF) && (key_s == OFF)) { ent_animate(my, "Standa", anim_percentage, ANM_CYCLE); // play the "stand" animation } else { ent_animate(my, "Walka", anim_percentage, ANM_CYCLE); // play the "walk" animation } anim_percentage += 8 * time_step; // 5 = animation speed wait (1); } } function main() { video_set(xmax,ymax,32,fscreen); screen_color.blue=0; screen_color.red=0; screen_color.green=0; wait(2); wait(-8); splash1.bmap=dhlogo; while(splash1.pos_x <= 125) { splash1.pos_x += 3 * time_step; wait(1); } toggle(mainmenu,VISIBLE); level_load("dh.wmb"); skycube = ent_createlayer("Sky_2+6.tga", SKY | CUBE | VISIBLE, 0); mouse_map= mcursor; mouse_mode = 2; //delay the inevitable while(key_pressed(key_for_str("q")) == 0) { //Process Mouse mouse_pos.x = mouse_cursor.x; mouse_pos.y = mouse_cursor.y; //if (player != NULL) { //I even tried putting the flicker causing code here //still works //still flickers // :( //} //next cycle wait(1); } sys_exit("p00!"); }
Thanks In Advance,
Neurosys