Gamestudio Links
Zorro Links
Newest Posts
Zorro 2.70
by jcl. 09/29/25 09:24
optimize global parameters SOLVED
by dBc. 09/27/25 17:07
ZorroGPT
by TipmyPip. 09/27/25 10:05
assetHistory one candle shift
by jcl. 09/21/25 11:36
Plugins update
by Grant. 09/17/25 16:28
AUM Magazine
Latest Screens
Rocker`s Revenge
Stug 3 Stormartillery
Iljuschin 2
Galactic Strike X
Who's Online Now
2 registered members (TipmyPip, 1 invisible), 18,699 guests, and 8 spiders.
Key: Admin, Global Mod, Mod
Newest Members
krishna, DrissB, James168, Ed_Love, xtns
19168 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Camera and VIEW #422151
05/03/13 08:30
05/03/13 08:30
Joined: Jul 2008
Posts: 168
8
82RJZAE Offline OP
Member
82RJZAE  Offline OP
Member
8

Joined: Jul 2008
Posts: 168
Hi, I'm having a little problem with simple multiplayer camera views. I would like to fix the current view on a player (as in first person) so that:

Code:
camera.x = player.x;
camera.y = player.y;
camera.z = player.z + 50;


But my problem is if I place the above code in the while loop for my player both the server client and client have the same camera view!

If I place the above code only within an if statement that is run by the client, the server client shows a correct view but the client view does not!

I read in old topics that camera is a global VIEW pointer and unlike the ENTITY* pointer, player, it is the same for all clients in multiplayer. How can I have separate views for each client so that they get their own camera view?

I have already tried creating new views on runtime via
Code:
reset(camera,VISIBLE);
  VIEW* my_view;
  my_view = view_create(1);
  wait(1);
  set(my_view,VISIBLE);


outside the main player while loop and then updating my_view.x/y/z to the player's x/y/z but the same thing happens.

The below code is the complete action for your reference. It is exactly the same code from workshop25 in Lite-C Tutorial with exception to the addition of the creation of VIEW* my_view and updating the view in the loop:

Code:
action player_move() // control the player on its client, move it on the server, animate it on all clients
{ 
  my.event = player_remove;
  my.emask |= ENABLE_DISCONNECT;
  my.smask |= NOSEND_FRAME; // don't send animation
   
  var walk_percentage = 0;
  var skill1_old = 0, skill2_old = 0;
  
  reset(camera,VISIBLE);
  VIEW* my_view;
  my_view = view_create(1);
  wait(1);
  set(my_view,VISIBLE);
  
  while (1) 
  {
    if (my.client_id == dplay_id)   // player created by this client?
    {
      if (key_w-key_s != my.skill1) { // forward/backward key state changed?
        my.skill1 = key_w-key_s; 
        send_skill(my.skill1,0); // send the key state in reliable mode
      }
      if (key_a-key_d != my.skill2) { // rotation key changed?
        my.skill2 = key_a-key_d; 
        send_skill(my.skill2,0); // send rotation state in reliable mode
      }
    	my_view.x = my.x;
		my_view.y = my.y;
		my_view.z = my.z + 50;
		my_view.pan = my.pan;
    }

    if (connection & CONNECT_SERVER) // running on the server?
    {
      if (my.skill1 != skill1_old) {    // if movement changed
        send_skill(my.skill1,SEND_ALL); // send movement to all clients
        skill1_old = my.skill1;
      }
      if (my.skill2 != skill2_old) {    // if rotation changed
        send_skill(my.skill2,SEND_ALL); // send rotation to all clients
        skill2_old = my.skill2;
      }
    }
    
    my.pan += my.skill2*5*time_step;   // rotate the entity using its skill2
    var distance = my.skill1*5*time_step;
    c_move(me, vector(distance,0,0), NULL, GLIDE | IGNORE_PASSABLE); // move it using its skill1
    walk_percentage += distance;
    ent_animate(me,"walk",walk_percentage,ANM_CYCLE); // animate the entity

    wait (1);
  }
}

Thanks in advance! laugh

Re: Camera and VIEW [Re: 82RJZAE] #422176
05/03/13 15:35
05/03/13 15:35
Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
Superku Offline
Senior Expert
Superku  Offline
Senior Expert

Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
You don't need the additional view, just write the camera.x = my.x; code in your (my.client_id == dplay_id) if clause.


"Falls das Resultat nicht einfach nur dermassen gut aussieht, sollten Sie nochmal von vorn anfangen..." - Manual

Check out my new game: Pogostuck: Rage With Your Friends
Re: Camera and VIEW [Re: Superku] #422189
05/03/13 20:50
05/03/13 20:50
Joined: Jul 2008
Posts: 168
8
82RJZAE Offline OP
Member
82RJZAE  Offline OP
Member
8

Joined: Jul 2008
Posts: 168
Right! Not sure why that wasn't working before! Thanks! laugh


Moderated by  HeelX, Spirit 

Gamestudio download | 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