

+++ Version 6.11 update available on download page +++ bones animation +++ new debugger +++ and more exciting features +++ get it today! +++ 
 
 
Main Index | Search | My Home | Who's Online | Help | Logout | User List | Mark all read  
 

Technical Topics >> Starting with Gamestudio   Previous     Index     Next     Flat     Threaded    
 
 
 

Pages: 1  
mystic80  
Junior Member  
 

 
Reged: Jun 13 2003  
Posts: 59  
 
  problem with camera code 
      #304251 - Sun Oct 12 2003 06:02 PM   Edit     Reply     Quote    
 
 

hi there

I have created a 3rd person camera mode but im having trouble wif on the part where the camera suppose to tilt instead of getting near to the player when the player gets near to the wall. can somebody help me with my code? thanks!

var dist_planar = 300; // distance from the player
var cam_angle = 0;
var dist_traced;
var cam_tilt = -20;
var cam_height = 120;

view 3rd_person
{
layer = 1;
pos_x = 0;
pos_y = 0;
}

function init_cameras()
{
camera.visible = off;
3rd_person.size_x = screen_size.x;
3rd_person.size_y = screen_size.y;
3rd_person.genius = player;
3rd_person.visible = on;
update_views();
}

function update_views()
{
3rd_person.x = player.x - cos (cam_angle) * dist_planar;
3rd_person.y = player.y - sin (cam_angle) * dist_planar;
3rd_person.z = player.z + cam_height;
3rd_person.pan = cam_angle;
3rd_person.roll = 0;
3rd_person.tilt = cam_tilt;
validate_view();
}

function validate_view()
{
trace_mode = ignore_me + ignore_passable;
dist_traced = trace (player.x, 3rd_person.x);
if (dist_traced == 0) { return; } // No obstacles hit... fine
if (dist_traced < dist_planar)
{
dist_traced -= 5; // Move it out of the wall
3rd_person.tilt -= (cam_height/dist_traced);
}
} 

Post Extras:            
Orange Brat  
Expert  
  
 
 
Reged: Aug 03 2000  
Posts: 1687  
 
  Re: problem with camera code [Re: mystic80] 
      #304262 - Sun Oct 12 2003 06:37 PM   Edit     Reply     Quote    
 
 

My now abandoned 3rd person code is based on what yours is based on...the bottom 4-5 lines need to be inside a player intentions type function...hopefully I reconstructed properly in this post. I took the "genius" part out since the alpha transparency won't work right. If you don't want that feature, then remove the call to it and put the genius line back in. Call the "init_cameras();" INSIDE your player action but BEFORE the player loop. The "move_cameras();" should be called after all animations have been taken care of and just before the player loop's wait instruction. 

Code:
--------------------------------------------------------------------------------

  
var correction = 10; // How much the cam is moved away from walls

var dist_planar; // Used for calculations
var dist_locked = 120; // behind player
var dist_dummy = 0;

var max_tilt = 85;
var min_tilt = -80;

var between[20];
var pushs[20];
var number_between;

var distance; // for me's transparency
var max_alpha = 50;
var min_alpha = 0;
var dist_full_vis = 50;
var dist_less_vis = 10;

view 3rd_cam 
{
 layer = 1;
 pos_x = 0;
 pos_y = 0;
}

function init_cameras()  
{
 camera.visible = off;
 3rd_cam.visible = on;
 3rd_cam.x = me.x - cos (me.pan) * dist_locked; 
 3rd_cam.y = me.y - sin (me.pan) * dist_locked;
 3rd_cam.z = me.z;
 3rd_cam.pan = me.pan;
 3rd_cam.roll = 0;	
 3rd_cam.tilt = 0;

 3rd_cam.size_x = screen_size.x; 
 3rd_cam.size_y = screen_size.y;	
}

function toggle_me_transparancy()
{
 if (distance > dist_full_vis)
 {
  me.alpha = 100;
  me.transparent = off;
  return;
 }
 me.transparent = on;
 temp = (max_alpha - min_alpha)/(dist_full_vis - dist_less_vis);
 me.alpha = temp * distance - dist_full_vis * temp + max_alpha;
 if (distance < dist_less_vis) { me.alpha = min_alpha; }
}

function move_cameras() 
{
 if(3rd_cam.visible == on)
 {
  dist_planar = fcos (tilt_locked, dist_locked);
  3rd_cam.x = me.x - fcos(me.pan + angle_locked, dist_planar);
  3rd_cam.y = me.y - fsin(me.pan + angle_locked, dist_planar);
  3rd_cam.z = me.z + fsin(tilt_locked, dist_locked);     
  3rd_cam.pan = me.pan + angle_locked;
  3rd_cam.roll = 0;
  3rd_cam.tilt = -tilt_locked;	
  validate_position();
  toggle_me_transparancy();
 }
}

function correct_pushs()
{
 while (number_between > 0)
 {
  number_between -= 1;
  you = ptr_for_handle(between[number_between]);
  you.push = pushs[number_between];
 }
}

function validate_position()
{
 number_between = 0;
 distance = dist_locked;
 trace_mode = ignore_me + ignore_passable;
 dist_dummy = trace(me.x, 3rd_cam.x);
 if (dist_dummy == 0) { return; }
 if (dist_dummy < dist_locked) 
 {
  while (you != null)
  {
   if ((you.invisible == on) && (you.passable == on))
   {
    between[number_between] = handle(you);
    pushs[number_between] = you.push;
    number_between += 1;
    you.push = my.push - 1;
    trace_mode = ignore_me + ignore_push + ignore_sprites;
    dist_dummy = trace(me.x, 3rd_cam.x);
    if ((dist_dummy >= dist_locked) || (dist_dummy == 0)) 
    { 
     correct_pushs(); 
     return; 
    }
   }
   else 
   { 
    you = null; 
   }
  wait(1);
  } 
 }
  dist_dummy -= correction;
  distance = dist_dummy;
  dist_planar = fcos (tilt_locked, dist_dummy);
  3rd_cam.x = me.x - fcos(me.pan + angle_locked, dist_planar);
  3rd_cam.y = me.y - fsin(me.pan + angle_locked, dist_planar);
  3rd_person_locked.z = me.z + fsin(tilt_locked, dist_dummy);		
  correct_pushs();
  return;
}

function mouse_cam(amount)
{
 if ((amount < 0) && (tilt_locked < max_tilt)) 
 { 
  tilt_locked -= amount; 
 }
  if ((amount > 0) && (tilt_locked > min_tilt)) 
  { 
   tilt_locked -= amount; 
  }
}

// Mouse controls camera...this stuff goes inside a separate player intentions function who's call should be inside the player action's loop:

var cursorx;
var mouse_invert = 1; //-1 inverts, 1 normal
var mouse_sensitivity = 2; //higher = more sensitive
var rotate_player = 8;  //Affects Player Rotation Speed
var rotate_input = 0;
DEFINE _rotspeed, skill45;


if (mouse_force.x != 0) 
{ 
 cursorx = mouse_force.x * mouse_sensitivity; 
}  

 rotate_input = -rotate_player * cursorx; 
 my._rotspeed = (time * rotate_input +max(1-time*0.7,0) * my._rotspeed);
 temp.pan = time * my._rotspeed;
 temp.tilt = 0;
 temp.roll = 0;
 rotate my,temp,nullvector;  

if (mouse_force.y != 0) 
{ 
 mouse_cam (mouse_force.y * mouse_invert * mouse_sensitivity); 
} 


--------------------------------------------------------------------------------


Here's an example of a player action using this: 

Code:
--------------------------------------------------------------------------------

  
action heromove
{
 wait(1);
 if (player == null) { player = me; } // Set the player synonym
 init_cameras();
 //my.fat = on;
 //my.narrow = on;
 .
 .
 .
 <other flag settings here>
 .
 .
 .
 while (1) 
 {
  .
 .
 .
 <other calls here>
 .
 .
 .
 move_cameras();       //update and validate camera
 wait(1);		
 }  
}


--------------------------------------------------------------------------------


--------------------
The Disenfranchised - click and learn about that Orange Brat guy's pet project 

Mafia - get the demo to one of the best games ever made 

Post Extras:            
mystic80  
Junior Member  
 

 
Reged: Jun 13 2003  
Posts: 59  
 
  Re: problem with camera code  [Re: Orange Brat] 
      #304480 - Mon Oct 13 2003 04:12 PM   Edit     Reply     Quote    
 
 

woah ur code seems a bit too tough for me....
i think i dun really understand some of it....

can u simpilfy it? i thot I post in the beginners forum. hehe..

 

Post Extras:            
Orange Brat  
Expert  
  
 
 
Reged: Aug 03 2000  
Posts: 1687  
 
  Re: problem with camera code  [Re: mystic80] 
      #304522 - Mon Oct 13 2003 06:54 PM   Edit     Reply     Quote    
 
 

It's exactly like yours just with a few more pieces. To be honest, there are a couple of parts I don't understand, either.  I simply tweaked Gnometech's version. 

With the exception of some wall clipping issues, it is a perfect 3rd person camera, plus the player fades as the camera moves closer to it. It doesn't go into the wall, it just clips it when it first hits the wall but glides as it should after that very first instant of clipping(and doesn't clip while gliding). 

--------------------
The Disenfranchised - click and learn about that Orange Brat guy's pet project 

Mafia - get the demo to one of the best games ever made 

Post Extras:            
Pages: 1  
 

 Previous     Index     Next     Flat     Threaded    
 
 

Extra information  
4 registered and 1 anonymous users are browsing this forum. 

Moderator:  Dan Silverman, Perro, Realspawn, Grayson Peddie, Tobias_Runde  

Favorite Thread! (toggle)
Print Thread 

 Permissions 
      You can start new topics 
      You can reply to topics 
      HTML is disabled 
      UBBCode is enabled 

 Rating: 
Thread views: 32 

 
          Rate this thread  1 star 2 star 3 star 4 star 5 star       Jump to  *Technical Topics* -----   Starting with Gamestudio   Level and Model Editing   Engine Topics   Scripting   Physics   Higher Languages   Shader Programming   Frequently Asked Questions   New Tutorials   Template Scripts*Feedback* -----   Engine Future   Engine Bug Hunt   Editors Future   Editors Bug Hunt   Blame the Manual   Ask Conitec   Announcements & Polls*Game Development* -----   General Topics   General Tools   Jobs Wanted   Jobs Offered   User Requests   User Contributions   Showcase   Contests*Miscellaneous* -----   Morbius' Foreign Affairs   Morbius' Virtual Answering Machine   Arena   Complaints Box   Guest Forum   
 


forum rules | info | faq | gallery | download | shop | links | news | resources | magazine | contest | support | bugs | beta | forecast

Conitec Datensysteme GmbH | Dieselstr. 11c | 64807 Dieburg, Germany | Tel +49 (6071) 9252-0 | Fax +49 (6071) 9252-33
Conitec Corporation | 1951 Fourth Ave, Ste. 301 | San Diego, CA 92101 | Tel +1 (619) 702-4420 | Fax +1 (619) 702-4419
contact@conitec.net | webmaster@conitec.net

