Stupid crosshair

Posted By: Liamissimo

Stupid crosshair - 01/24/11 23:02

Hey Guys,

I need your help. I already checked out many crosshair examples, also from the aum. But I have a barricade in my head. I have a crosshair in the middle of the screen and an object who should shoot at the crosshair. Crosshair is a panel and I know I have to use vec_for/to_screen but I just don't get it, barricade, as I said grin

I just have to calculate the direction vector from my camera.x to the 2D Crosshair and use vec_diff to adjust the bullet to this position?
Posted By: Superku

Re: Stupid crosshair - 01/24/11 23:09

Beschreib's noch mal bitte auf deutsch.
Posted By: HeelX

Re: Stupid crosshair - 01/24/11 23:12

This is the answer that doesn't ask you anything:

vec_for_screen calculates a 3D position in world space, so, if you use it with VECTOR->z = 0, the position should be directly on the camera plane. Other than that, use the VIEW->clip_near distance as Z-parameter to make sure that the bullet is created in such a frontal distance, that it is seen in the very first frame.

This is the answer with some silly questions:

Why would you create the bullet at the crosshair? I believe that the player wants to -hit- the spot with the weapon on which the crosshair points. It is also obvious, that if you are empowering the user with a common weapon, he or she might expect that the weapon (if not visible on the screen) is hold beneath the screen on the left or right side, so, create the bullet at the muzzle and -trace- from there to the point where the crosshair points to, to analyze the line of fire instead of penetrating with c_move the worldspace with such a small collision hull a typical vanilla bullet has (just in the case if you are not shooting with watermelons smile).
Posted By: Liamissimo

Re: Stupid crosshair - 01/24/11 23:20

No, no watermelons. Well, I don't know what to insert.

Also im Grunde habe ich ein 2D Punkt zu dem ich schiessen will, Fadenkreusz eben, kennt man, mag man wink Jetzt steh ich nur TOTAL auf dem Schlauch wie ich es in Lite-C hinbekomme dorthin zu schiessen. Ich verstehe das Prinzip aber stehe eben total auf dem Schlauch, sehr ärgerlich sowas. Wäre toll wenn mir jemand nur den Part schreiben könnte der mit dem vec_to_screen zu tun hat, jegliche Denkanstöße scheitern bei mir gerade.
Posted By: Superku

Re: Stupid crosshair - 01/24/11 23:35

Das Fadenkreuz ist also nicht im Mittelpunkt des Bildschirms? Sollte das Fadenkreuz die Maus sein, ist es sehr einfach:

// use the mouse to trace a ray into the level,
// and trigger EVENT_SHOOT of hit entities
function shoot_with_mouse()
{
VECTOR to;
vec_set(to,mouse_dir3d);
vec_scale(to,1000); // set a range
vec_add(to,mouse_pos3d);
c_trace(mouse_pos3d,to,ACTIVATE_SHOOT);
}

(Manual-Beispiel zu mouse_pos3d)
Posted By: Liamissimo

Re: Stupid crosshair - 01/24/11 23:36

Doch, das Fadenkreuz ist genau in der Mitte des Bildschirmes und nicht Veränderbar, den Code hätte ich sonst sofort genommen wink
Posted By: HeelX

Re: Stupid crosshair - 01/24/11 23:37

Something like this?

Code:
VECTOR ptFarAway, ptOnCamera;
vec_set(&ptFarAway,  vector(mouse_cursor.x, mouse_cursor.y, camera->clip_far));
vec_set(&ptOnCamera, vector(mouse_cursor.x, mouse_cursor.y, camera->clip_near));

c_trace(&ptOnCamera, &ptFarAway, ...);

VECTOR ptHit;
vec_set(&ptHit, hit->x);

ENTITY* bullet = ent_create("bullet.mdl", &ptOnCamera, objBullet);
vec_set(bullet->skill1, &ptFarAway);

void objBullet ()
{
   wait(1); // wait until skill1,2,3 are filled with destination
   
   while (1)
   {
      VECTOR destination;
      vec_set(&destination, my->skill1); //2,3

      // fly to destination
      
      // if to near, break

      wait(1);
   }
   
   ptr_remove(my);
}


Posted By: HeelX

Re: Stupid crosshair - 01/24/11 23:37

Originally Posted By: TheLiam
Doch, das Fadenkreuz ist genau in der Mitte des Bildschirmes und nicht Veränderbar, den Code hätte ich sonst sofort genommen wink


Dann musst du screen_size.x/2 und .y/2 einsetzen!

Oder du rotierst einen Einheits-Vektor mit dem Kamera-Pan und hast die Richtung...
Posted By: Liamissimo

Re: Stupid crosshair - 01/24/11 23:39

Im mouse_dir Beispiel? Dein Code sieht sehr profesionell aus, ich weiß allerdings nicht was ein "&" am Anfang bedeutet und was ein "->" bewirkt wink

Code:
function plasmaball()
{
	VECTOR temp;
	VECTOR temp2;
	vec_set(temp,camera.x);
	vec_add(temp,vector(1000,400,300));
	vec_rotate(temp,you.pan);
	vec_to_angle(my.pan,temp);
	while(me)
	{
		c_move(me,vector(200*time_step,0,0), nullvector,IGNORE_YOU);
		wait(1);
	}
}


Das ist Gerade mein Code, bestimmt der letzte Mist. Ich schiesse gerade nahc links oben...wtf?
Posted By: Superku

Re: Stupid crosshair - 01/24/11 23:46

So schießt du ins Bild-Zentrum:

vec_set(temp,vector(Schuss-Reichweite,0,0));
vec_rotate(temp,camera.pan);
vec_add(temp,camera.x);
c_trace(camera.x,temp,...);

Fliegt deine Kugel, sprich hast du eine Kugel-Entity, so erstelle sie einfach auf camera.x-Position und setze vec_set(kugel.pan,camera.pan); einmalig nach Erstellung.
Posted By: Liamissimo

Re: Stupid crosshair - 01/24/11 23:51

Jetzt kommt garnichts mehr bei mir.
Das rote soll zum weißen Crosshair schiessen.

© 2024 lite-C Forums