Gamestudio Links
Zorro Links
Newest Posts
Help with plotting multiple ZigZag
by degenerate_762. 04/30/24 23:23
M1 Oversampling
by 11honza11. 04/30/24 08:16
Trading Journey
by howardR. 04/28/24 09:55
Zorro Trader GPT
by TipmyPip. 04/27/24 13:50
Data from CSV not parsed correctly
by jcl. 04/26/24 11:18
Why Zorro supports up to 72 cores?
by jcl. 04/26/24 11:09
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
4 registered members (AndrewAMD, SBGuy, TipmyPip, ozgur), 923 guests, and 6 spiders.
Key: Admin, Global Mod, Mod
Newest Members
firatv, wandaluciaia, Mega_Rod, EternallyCurious, howardR
19050 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Good N Simple 3rd person cam controller for ur projects !!! #429503
09/13/13 12:49
09/13/13 12:49
Joined: Jul 2008
Posts: 2,107
Germany
rayp Offline OP

X
rayp  Offline OP

X

Joined: Jul 2008
Posts: 2,107
Germany
Hi.
Because its almost the same question...

Heres a simple ( but well working...i guess ^^ ) 3rd person cam controller which takes care of walls and obstacles via c_trace. Maybe u need to play around with campos1 and campos2 values to fit ur needs. Thanks to SuperKu, cause he provited me the required tips for the c_trace part a few month ago. If uve optimized something, POST U MISER(S) ! grin

Code:
// 3rd person cam controller written by rayp 2013
// -------------------------------------------------------------------------------------------------------------------------------------------------
var cam_lerp = 0;  // global!
void _handle_cam_3rdperson(){
   VECTOR cam_pos1,cam_pos2;
   var i;
   // -------------------------------------------------------------------
   vec_set(cam_pos1,vector(-300, 0, 5)); // First cam pos
   vec_rotate(cam_pos1,vector(player.pan,camera.tilt-15,0));
   vec_add(cam_pos1,player.x);
   // -------------------------------------------------------------------
   vec_set(cam_pos2,vector(-20, 0, 30)); // Second cam pos  
   vec_rotate(cam_pos2,vector(player.pan,-5,0));
   vec_add(cam_pos2,player.x);
   // -------------------------------------------------------------------
   //if u handle cam tilt/pan + playerpan somewhere else remove the following four lines. Its pan and tilt handling, not more.
   //turn player via mouse mickey.x
   c_rotate(me, vector(-mickey.x * time_step / 4,0,0), IGNORE_ME | IGNORE_PASSABLE | IGNORE_SPRITES | USE_POLYGON | GLIDE);
   //set cam pan 2 player pan
   camera.pan = my.pan;
   camera.tilt += mickey.y * time_step;
   camera.tilt = clamp (camera.tilt, -45, 45); //not tested play around with the values here
   // -------------------------------------------------------------------      
   trace_mode = IGNORE_ME | IGNORE_PASSABLE | IGNORE_SPRITES | USE_POLYGON;   
   c_ignore (1, 0); // cam ignores the player
   i = c_trace(cam_pos2,cam_pos1, trace_mode); //trace from campos to campos
   if(!trace_hit) i = 1;
   else i = i/vec_dist(cam_pos1,cam_pos2);      

   if (i < 0.1) set  (player, TRANSLUCENT); //very close to player? set him transparent
   else         reset(player, TRANSLUCENT); //far away reset transparent
   // -------------------------------------------------------------------
   //calculate camera pos
   i = i / 3;
   cam_lerp = minv(cam_lerp+0.125*time_step,i);
   vec_lerp(camera.x,cam_pos2,cam_pos1,cam_lerp);//at the end set camera x
}
// -------------------------------------------------------------------------------------------------------------------------------------------------



Example call in your project
Code:
void move_player(){
   player = me;
   my.group = 1; 
   ...
   ..
   while (1){     
      ...
      ..
      c_move()
      _handle_cam_3rdperson();
      ..
      ...
      wait (1);
   }
   ..
   ...
}

...when copy and pasting at least credits would be nice

edit:
Its not good to turn player via c_rotate ( dont know why i wrote it in the code ). Use "player.pan += ..." instead. When using c_rotate, player will stuck while looking around, in some situations.


Acknex umgibt uns...zwischen Dir, mir, dem Stein dort...
"Hey Griswold ... where u gonna put a tree that big ?"
1998 i married my loved wife ... Sheeva from Mortal Kombat, not Evil-Lyn as might have been expected
rayp.flags |= UNTOUCHABLE;
Re: Good N Simple 3rd person cam controller for ur projects !!! [Re: rayp] #429535
09/13/13 20:35
09/13/13 20:35
Joined: Mar 2003
Posts: 4,264
Wellington
Nems Offline

.
Nems  Offline

.

Joined: Mar 2003
Posts: 4,264
Wellington
laugh Thanks, will try it out later ish....currently using KH_Movement cam, works great...


Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1