Catching Crosshairs

Posted By: Razoron

Catching Crosshairs - 02/15/10 18:04

Hey guys,
I have no idea how I could make the crosshair in my dogfight game catching near other planes. Any idea how to code this?
Posted By: jane

Re: Catching Crosshairs - 02/15/10 19:44

Hallo,
wie wäre es hiermit:

PANEL* Visier =
{
layer = 1;
bmap = "dein sprite"
flags = OVERLAY;
scale_x = deine grösse;
scale_y = deine grösse;
}

function show_visier()
{
set(visier, SHOW);
visier.pos_x = screen_size.x/2 -(16*visier.scale_x);
visier.pos_y = screen_size.y/2 -(16*visier.scale_y);
}

function hide_visier()
{
reset(visier, SHOW);
}

Mit der 16 rumspielen bis die Größe gefällt.

Gruß Jane
Posted By: MasterQ32

Re: Catching Crosshairs - 02/15/10 20:42

ich glaub, ehr meint das hier:
Code:
PANEL* pan_crosshair = 
{
	bmap = your_bmap;
}

ENTITY* nearest_plane;

function crosshair()
{
	VECTOR temp;
	while(1)
	{
		if(nearest_plane != NULL) // check if nearest plane exists
		{
			vec_set(temp,nearest_plane.x);
			if (vec_to_screen(temp,camera) != NULL) // if visible on screen, convert to screen coordinates
			{
				pan_crosshair.pos_x = integer(temp.x - bmap_width(your_bmap) / 2); // place the crosshair
				pan_crosshair.pos_y = integer(temp.y - bmap_height(your_bmap) / 2);;
				set(pan_crosshair,SHOW);
			} 
			else 
			{
				reset(pan_crosshair,SHOW);
			}
		}
		else 
		{
			reset(pan_crosshair,SHOW);
		}
		wait(1);
	}
	
}

action plane()
{
	while(me)
	{
		if(vec_dist(my.x,camera.x) < vec_dist(nearest_plane.x,camera.x)) // Check if not the nearest plane
			nearest_plane = me; // Set to the nearest plane
		wait(1);
	}
}



Replace your_bmap with the crosshair bmap.
The nearest_plane is the entity which has the crosshair on it.
Posted By: Razoron

Re: Catching Crosshairs - 02/15/10 21:20

Nice ideas of you, but this doesn't make sense:
Code:
action plane()
{
	while(me)
	{
		if(vec_dist(my.x,camera.x) < vec_dist(nearest_plane.x,camera.x)) // Check if not the nearest plane
			nearest_plane = me; // Set to the nearest plane
		wait(1);
	}
}


nearest_plane might be the nearest plane of the camera, but not the nearest plane of the crosshair. The player can also Shoot planes, which aren't the neartest of the camera, just the nearest to the crosshair.

Nochmal in deutsch:
Der Spieler kann doch aber auch das Flugzeug, was am meisten weg ist abschiessen und darauf zielen. Wenn direkt hinter ihm ein anderer ist, ist nearest_plane zwar dieser Gegner, aber das, was er eigentlich abschiessen will ist vielleicht ein anderer.

EDIT: Oder nochmal ein anders Beispiel:
Das Crosshair ist in der Mitte des Bildschirms. Jetzt fliegt ein anderes, feindliches Flugzeug an ihm vorbei. Das Flugzeug befindet sich vielleicht mit vec_to_screen 30 pixel weiter auf der X-Achse vom Crosshair entfernt. Der Crosshair schlägt aus und bewegt sich 30 pixel nach rechts, sodass er auf das Flugzeug, den Gegner zeigt. Der Gegner muss aber nicht der nähste Gegner sein.
Posted By: MasterQ32

Re: Catching Crosshairs - 02/15/10 21:24

Du must einfach einen Code in die Art machen.
Wenn die Distanz vom Flugzeug zu bezielten Flugzeug kleiner als ist, als die Distanz zum nächstnähesten Flugzeug, selektiere dieses Flugzeug.
Iwie so
Posted By: MasterQ32

Re: Catching Crosshairs - 02/15/10 22:43

also so:
Code:
action plane_nearto_screen()
{
	VECTOR temp;
	while(me)
	{
		vec_set(temp,my.x);
		if (vec_to_screen(temp,camera) != NULL) // if visible on screen, convert to screen coordinates
		{
			if(vec_dist(temp,vector(screen_size.x / 2,screen_size.y / 2,0)) < 30) // Distanz zur Bildschirmmitte kleiner 30
			{
				nearest_plane = me; // Set to the nearest plane
			}
		} 
		wait(1);
	}
}


Posted By: Razoron

Re: Catching Crosshairs - 02/16/10 15:37

Gut, gut ich probiers aus. laugh
Posted By: MasterQ32

Re: Catching Crosshairs - 02/17/10 22:02

kleine frage:
gehts?
© 2023 lite-C Forums