Kamera in Multiplayer/Cam in Multiplayer

Posted By: virtualmarctek

Kamera in Multiplayer/Cam in Multiplayer - 07/01/08 21:56

Deutsch:
Ich möchte eine 1st Person kamera im Multiplayer machen, aber irgendwie funktionierts nicht. Der Code wird ausgeführt, nachdem sich der Player bewegt hat.

English:
I would like to create a 2st person camera in multiplayer, but it doesn work. The code ist started after moving the player.

Code:
function pl_cam()
{
	camera.pan = player.pan;
	camera.tilt = 0;
	camera.roll = 0;
	camera.x = player.x;
	camera.y = player.y;
	camera.z = player.z;
}

Posted By: DJBMASTER

Re: Kamera in Multiplayer/Cam in Multiplayer - 07/01/08 23:11

This code shows nothing useful. We need more info on how you start the server/clients.
Posted By: virtualmarctek

Re: Kamera in Multiplayer/Cam in Multiplayer - 07/02/08 08:23

Here is the full code:
Code:
#include <acknex.h>
#include <default.c>
#include "status.c"
#include "windows.h"
#include "d3d9.h"


//---------------------------------------------------------------------------------------------||
// some global vars, defines...
//---------------------------------------------------------------------------------------------||
#define force_x skill1
#define force_y skill2
#define force_z skill3
#define force_pan skill4
#define MAX_CONNECTIONS 8

VECTOR camVel;
var force[3];
var vecFrom[3];
var vecTo[3];


//---------------------------------------------------------------------------------------------||
// function prototypes
//---------------------------------------------------------------------------------------------||
void playerAct();
void inputs();
void server_called();
void client_called();
void donothing(){wait(1);}


//---------------------------------------------------------------------------------------------||
// main function
//---------------------------------------------------------------------------------------------||
int main()
{
	video_mode = 8;
	video_depth = 32;
	video_screen = 2;
	fps_max = 60; // lock fps at 60 for all players
	fps_lock = ON;
	dplay_smooth = 0; // dplay_smooth is causing too much overshoot and jerks
	
	on_server = server_called; // on server event, call server_called()
   on_esc = donothing;
   
   wait(-.3);
   if(connection == 3){
   	people_connected = 1;
   	str_cpy(messages_str, "Connecting as a HOST...");
   	wait(-3);
   	reset(messages_txt, VISIBLE);
   	set(connected, VISIBLE);
   	set(status, VISIBLE);
   	video_window(NULL,NULL,16,"HOST...");
   }
   if(connection == 2){
   	str_cpy(messages_str, "Connecting as a CLIENT...");
   	wait(-3);
   	reset(messages_txt, VISIBLE);
   	set(connected, VISIBLE);
   	set(status, VISIBLE);
   	video_window(NULL,NULL,16,"CLIENT...");
	}

   level_load("test.wmb");
   wait(-.3);
   player = ent_create("aim.mdl", vector(0,0,100), playerAct);
   
   wait(-.3);
   
   inputs();
   
    
   while(1)
	{
		again:
		// constantly checks if server is still online
		if(dplay_bps == 0 && dplay_latency == 0 && connection == 2)	{
			if (MessageBox(NULL, "Server is offline and the game will shutdown.", "Error", MB_OK | MB_ICONSTOP) == IDOK){
				sys_exit(NULL);
			}
		}
		if(key_esc){
			while(key_esc){wait(1);}
			if(MessageBox(NULL, "Do you really want to quit?", "Quit?", MB_YESNO | MB_ICONQUESTION) == IDYES){sys_exit(NULL);}
				else{wait(1);goto again;}
		}
		wait(1);
	}
}


//---------------------------------------------------------------------------------------------||
// function for handling inputs
//---------------------------------------------------------------------------------------------||
void inputs()
{
	while(1){
		player.force_x = (key_w - key_s) * time_step * 15;
		player.force_y = (key_a - key_d) * time_step * 15;
		player.force_pan -= mouse_force.x * 15 * time_step;
		
		if(connection == 2){
			send_skill(player.force_x, SEND_VEC);
			send_skill(player.force_pan, 0);
		}
		
		wait(1);
	}
}


//---------------------------------------------------------------------------------------------||
// Kamera Funktion
//---------------------------------------------------------------------------------------------||
function pl_cam()
{
	camera.pan = player.pan;
	camera.tilt = 0;
	camera.roll = 0;
	camera.x = player.x;
	camera.y = player.y;
	camera.z = player.z;
}


//---------------------------------------------------------------------------------------------||
// move player function
//---------------------------------------------------------------------------------------------||
void movePl()
{
	while(1){
		my.pan = my.force_pan;
	
		force[0] = my.force_x * 15 * time_step;
		force[1] = my.force_y * 10 * time_step;
		force[2] = 0;
		
		move_mode = GLIDE|IGNORE_PASSABLE|IGNORE_PASSENTS|IGNORE_YOU;
		c_move(my, force, nullvector,move_mode);
		
		if (my.force_x || my.force_y || my.force_z)
		{
			trace_mode = IGNORE_SPRITES|IGNORE_PASSENTS|IGNORE_PASSABLE|IGNORE_MODELS|USE_BOX;
			vec_set(vecFrom,my.x);
			vec_set(vecTo,my.x);
			vecTo[2] -= 400;
			result = c_trace(vecFrom,vecTo,trace_mode);
			my.z = target.z + ((my.max_z - my.min_z)/2);//Set to the floor
		}
		pl_cam();
		wait(1);
	}
}


//---------------------------------------------------------------------------------------------||
// player action
//---------------------------------------------------------------------------------------------||
action playerAct()
{
	my.emask |= ENABLE_DISCONNECT;
	my.smask |= NOSEND_FRAME;
	
	c_setminmax(my);
	
	wait(-.3);
	ent_sendnow(my);
	wait(-.3);

	set(me, SHADOW);
	movePl();
}


//---------------------------------------------------------------------------------------------||
// function Server_Called(): server was called
//---------------------------------------------------------------------------------------------||
void server_called()
{
	if ((event_type == EVENT_JOIN) && (people_connected < MAX_CONNECTIONS))
	{
		people_connected += 1; // another person connected
		send_var(people_connected); // send number of people connected
	}
	if (event_type == EVENT_LEAVE)
	{
		people_connected -= 1; // one less person connected to server
		send_var(people_connected); // send number of people connected
	}
}


//--------------------------------------------------------------------
// player events
//--------------------------------------------------------------------
void player_events()
{
	if (event_type == EVENT_DISCONNECT)
	{
		ent_remove(me); // remove ent of player that quit
	}
}


There is no Host (-sv -cl) only a Server (-sv) and a Client (-cl)
Posted By: croman

Re: Kamera in Multiplayer/Cam in Multiplayer - 07/02/08 08:29

ooh, that's my code smile put pl_cam(); under inputs(); in main function and add inside pl_cam function while loop...i'm not sure if that'll work but try it...
Posted By: virtualmarctek

Re: Kamera in Multiplayer/Cam in Multiplayer - 07/02/08 08:39

yes its your code, becaus I read it and i understand it. Its not so big like Locoweeds code wink

And now my result:
It works, I just have to make the camera higher, but thats no problem, because the cam is on the roof.
Posted By: croman

Re: Kamera in Multiplayer/Cam in Multiplayer - 07/02/08 08:43

so...this what i told you is working? does it work on client too?
Posted By: virtualmarctek

Re: Kamera in Multiplayer/Cam in Multiplayer - 07/02/08 09:01

i have only a client and a server no host!
Posted By: virtualmarctek

Re: Kamera in Multiplayer/Cam in Multiplayer - 07/04/08 08:02

Now there is a problem with the 3rd Person Camera. While I turn around the cam I see the player more times for short.

Here's my code:
Code:
//---------------------------------------------------------------------------------------------||
// 3rd Person Kamera Funktion
//---------------------------------------------------------------------------------------------||
var pan1;
var pan2;

void pl_cam()
{
	while(1) {
		pan1=cos(camera.pan)*300;
		pan2=sin(camera.pan)*300;
		camera.pan = player.pan;
		camera.x = player.x-pan1;
		camera.y = player.y-pan2;
		camera.z = player.z + 80;
		wait(1);
	}
}

Posted By: croman

Re: Kamera in Multiplayer/Cam in Multiplayer - 07/04/08 09:22

well...again, that problem you caused, no offens. something's wrong with your camera or/and with your player turning left,right... post here part of your code where the player is paning and where you call camera function
Posted By: virtualmarctek

Re: Kamera in Multiplayer/Cam in Multiplayer - 07/04/08 09:23

its the same with the 1st person camera only the cameracode is changed form 1st person in 3rd person!
Posted By: croman

Re: Kamera in Multiplayer/Cam in Multiplayer - 07/04/08 10:24

i really don't know why that happens to you but my 3rd person camera worked just fine. try creating different code for 3rd person camera, with other method...
Posted By: virtualmarctek

Re: Kamera in Multiplayer/Cam in Multiplayer - 07/04/08 10:34

ok I will try with another code, but in singleplayer isn't this problem.
Posted By: croman

Re: Kamera in Multiplayer/Cam in Multiplayer - 07/04/08 10:35

does this happens both on server and client or not?
Posted By: virtualmarctek

Re: Kamera in Multiplayer/Cam in Multiplayer - 07/04/08 10:37

the server is only dedicated but I can try to recreate the host
Posted By: croman

Re: Kamera in Multiplayer/Cam in Multiplayer - 07/04/08 10:39

try with host and client test
Posted By: virtualmarctek

Re: Kamera in Multiplayer/Cam in Multiplayer - 07/04/08 10:42

As Host is no problem, only as client!
Posted By: croman

Re: Kamera in Multiplayer/Cam in Multiplayer - 07/04/08 10:45

from where are you calling camera function?
Posted By: virtualmarctek

Re: Kamera in Multiplayer/Cam in Multiplayer - 07/04/08 10:53

from main unter input()
Posted By: croman

Re: Kamera in Multiplayer/Cam in Multiplayer - 07/04/08 11:02

okay, i maybe know what your problem is but i need to see that error. record small video of that error and upload it and post here link of that video.
Posted By: virtualmarctek

Re: Kamera in Multiplayer/Cam in Multiplayer - 07/04/08 11:12

Heres the Video:http://virtualmarctek.ath.cx/videos/error.html But there you don't the the player more times but you see it lag!
Posted By: croman

Re: Kamera in Multiplayer/Cam in Multiplayer - 07/04/08 11:40

well...i believe that's problem with your camera or...when testing on one pc clients are running "slowly", not smoothly, at least on my pc is like that, so maybe that's the problem.

but try with different code for 3rd person camera...
Posted By: virtualmarctek

Re: Kamera in Multiplayer/Cam in Multiplayer - 07/04/08 11:42

ok, I will look for another code. My PC can't be the problem:
CPU: Intel Core2Duo @ 1,95 Gh/z (overclocked fron 1,86) - 2 Core
GPU: nVidia Geforce 8800 GTS
Posted By: croman

Re: Kamera in Multiplayer/Cam in Multiplayer - 07/09/08 18:46

your camera code was a problem for sure. i tried it and it was buggy. wrong code for camera you had.
Posted By: virtualmarctek

Re: Kamera in Multiplayer/Cam in Multiplayer - 08/03/08 18:53

yes its a single player camera code
© 2024 lite-C Forums