Gamestudio Links
Zorro Links
Newest Posts
Executing Trades on Next Bar Open
by vicknick. 06/13/24 08:51
Zorro Beta 2.61: PyTorch
by jcl. 06/10/24 14:42
New FXCM FIX Plugin
by flink. 06/04/24 07:30
AlpacaZorroPlugin v1.3.0 Released
by kzhao. 05/22/24 13:41
Free Live Data for Zorro with Paper Trading?
by AbrahamR. 05/18/24 13:28
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
1 registered members (monarch), 1,259 guests, and 5 spiders.
Key: Admin, Global Mod, Mod
Newest Members
AemStones, LucasJoshua, Baklazhan, Hanky27, firatv
19059 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Confusion about vel_x #251512
02/13/09 13:22
02/13/09 13:22
Joined: Jan 2009
Posts: 34
D
DrunkenPirate Offline OP
Newbie
DrunkenPirate  Offline OP
Newbie
D

Joined: Jan 2009
Posts: 34
Hello,
I'm trying to create a solid laser line that shoots from the ship to a certain distance via the mouse. Here is my code:

Code:
function weapon_fire() {
	vec_for_vertex (gunLeft, player, 679);
	vec_for_vertex (gunRight, player, 737);
	if (mouse_left) {
		if (laserActive != 1) {
			tracer = ent_create("bullet.mdl",nullvector,NULL);
			effect (weapon_laser, 1, gunLeft, nullvector);
		}
		laserActive = 1;	
	}
	
}

//Laser weapon
function weapon_laser(PARTICLE* p) {
		p.flags |= (BRIGHT | BEAM | TRANSLUCENT);
		p.event = laser_fade;	//Move to faster function
		p.size = 0.3;
		p.bmap = laser; //the effect bitmap	
}

function laser_fade(PARTICLE* p) {
	if (mouse_left == 0) {
		p.lifespan = 0;
		laserActive = 0;
	}else{
		p.lifespan = 100;
		vec_set(p.x,gunLeft);
		vec_set(mouseTemp,vector(mouse_pos.x,mouse_pos.y,200));
		vec_for_screen(mouseTemp,camera);
		vec_set(temp,mouseTemp);
		vec_set(p.vel_x,temp);
		vec_set(tracer.x,temp);
	}
}


The "tracer" object works fine and stays at the mouse position as it should. The particle line does not. It moves when the mouse is moved (as it should) but it does not always shoot at the mouse. (Often times the laser will be shooting below the plane when the mouse is to the left of it, etc)

Thank you

Re: Confusion about vel_x [Re: DrunkenPirate] #251611
02/14/09 04:10
02/14/09 04:10
Joined: Jan 2009
Posts: 34
D
DrunkenPirate Offline OP
Newbie
DrunkenPirate  Offline OP
Newbie
D

Joined: Jan 2009
Posts: 34
I guess my post wasn't that clear.

I'm trying to have a laser shoot from the ship's guns to the mouse, which is the aiming device. p.vel_x needs to be static, I think, because that would be the length of the laser.

The tracer I was talking about was simply an object I put in that always at the mouse position, 200 quants away from the camera. This was to ensure that it was a particle velocity confusion and not a problem with my mouse vec_for_screen code block.

My problem is that the laser does not shoot towards the mouse.

Re: Confusion about vel_x [Re: DrunkenPirate] #251874
02/15/09 12:02
02/15/09 12:02
Joined: Jan 2009
Posts: 34
D
DrunkenPirate Offline OP
Newbie
DrunkenPirate  Offline OP
Newbie
D

Joined: Jan 2009
Posts: 34
Here is a working script for anyone who needs it:

Code:
//**********************WEAPON MASTER*********************//
//***
//**************************END***************************//


//************************INCLUDES************************//

//**************************END***************************//


//**************************NOTES*************************//
//***No Notes.
//**************************END***************************//


//**************************TODO**************************//
//***No Todo
//**************************END***************************//


//********************GLOBAL VARIABLES********************//
//***Any global variables go here. This is NOT the place
//***for entities or other such declarations.
VECTOR gunLeft;
VECTOR gunRight;
var laserActive;
VECTOR mouseTemp;
VECTOR laserDir; //Direction the space dust blows
VECTOR pPos;

//**************************END***************************//


//************************ENTITIES************************//
//***All entity declarations go here. (Unless local only!)
ENTITY* bullet;
ENTITY* tracer;
//**************************END***************************//


//************************FUNCTIONS***********************//
//***All function declarations go here.
function weapon_fire(); //Fires the weapons
function weapon_laser(PARTICLE* p);	//Fires the laser
function laser_fade(PARTICLE* p);	//Turns off the laser
//**************************END***************************//


//********************OTHER DECLARATIONS******************//
//***All other declarations like panels, sprites, etc
//***get thrown in here. Keep them organized in sections!
BMAP* laser = "laser_blue.tga";
//**************************END***************************//


//**********************FUNCTION CODE*********************//
//***All function code goes here. Try to keep this neat and
//***write your functions in groups in seperate files if
//***possible.
//Fires the weapons
function weapon_fire() {
	vec_for_vertex (gunLeft, player, 679);
	vec_for_vertex (gunRight, player, 737);
	if (mouse_left) {
		if (laserActive != 1) {
			tracer = ent_create("bullet.mdl",nullvector,NULL);
			effect (weapon_laser, 1, gunLeft, nullvector);
		}
		laserActive = 1;	
	}
	
}

//Laser weapon
function weapon_laser(PARTICLE* p) {
	p.flags |= (BRIGHT | BEAM | TRANSLUCENT);
	p.event = laser_fade;	//Move to faster function
	p.size = 0.6;
	p.bmap = laser; //the effect bitmap	
}

function laser_fade(PARTICLE* p) {
	if (mouse_left == 0) {
		p.lifespan = 0;
		laserActive = 0;
		}else{
		p.lifespan = 100;
		vec_set(p.x,gunLeft);
		vec_set(mouseTemp,vector(mouse_pos.x,mouse_pos.y,2000));
		vec_for_screen(mouseTemp,camera);
		
		vec_set(pPos,mouseTemp); //Sets the position to the camera
		
		temp.x = cos(camera.pan);	//Computes for pan & tilt
		temp.y = sin(camera.pan);
		temp.z = 600*cos(camera.tilt);
		
		pPos.x = pPos.x + temp.z*temp.x;	//Sets the final positions
		pPos.y = pPos.y + temp.z*temp.y;
		pPos.z = pPos.z + 600*sin(camera.tilt);
		
		vec_set(laserDir,camera.x); //Sets the vector to camera pos
		vec_sub(laserDir,pPos.x);	//Subtracts the position of the emitter
		//vec_scale(laserDir,0.05);	//Scales the vector, so things don't go too fast.
		vec_inverse(laserDir);		
		vec_set(p.vel_x,laserDir);
		vec_set(tracer.x,laserDir);
	}
}
//**************************END***************************//



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