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
1 registered members (TipmyPip), 18,466 guests, and 6 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
Random Spray (Angle) #406509
08/22/12 09:16
08/22/12 09:16
Joined: Jul 2008
Posts: 168
8
82RJZAE Offline OP
Member
82RJZAE  Offline OP
Member
8

Joined: Jul 2008
Posts: 168
Hi, how might I add randomness to the angle of a bullet (c_trace bullet) originating from camera.x to simulate bullet spread? I am using the below method to create bullets:

bullet_create(camera.x,camera.pan,500);

Originally Posted By: Superku
Code:
void bullet_create(VECTOR* vpos,VECTOR* vang,var speed)
{
	var alive = 16;
	VECTOR pos,temp,vel;
	
	vec_set(pos,vpos);
	vec_set(vel,vector(speed,0,0));
	vec_rotate(vel,vang);

	while(alive > 0)
	{
		// calculate new position
		vec_set(temp,vel);
		vec_scale(temp,time_step);
		vec_add(temp,pos);
		c_trace(pos,temp,IGNORE_PASSABLE | USE_POLYGON); // optional: SCAN_TEXTURE
		if(trace_hit)
		{
			/*if(you) ... // reduce health, blood effect
			else ... // spark effect*/
			alive = 0;
		}
		effect(p_bullet,1,pos,vel); // you may want to shorten vel on impact
		vec_set(pos,temp); // move to new position

		alive -= time_step;
		wait(1);
	}
}


My apologies I am not too familiar with vector mathematics.

Re: Random Spray (Angle) [Re: 82RJZAE] #406510
08/22/12 09:50
08/22/12 09:50
Joined: Nov 2007
Posts: 2,568
Germany, BW, Stuttgart
MasterQ32 Offline
Expert
MasterQ32  Offline
Expert

Joined: Nov 2007
Posts: 2,568
Germany, BW, Stuttgart
just randomize your shooting direction a little bit:
vang.x += random(spray) - spray / 2;
vang.y += random(spray) - spray / 2;

spray is the total spraying angle


Visit my site: www.masterq32.de
Re: Random Spray (Angle) [Re: MasterQ32] #406513
08/22/12 11:30
08/22/12 11:30
Joined: May 2009
Posts: 5,377
Caucasus
3run Offline
Senior Expert
3run  Offline
Senior Expert

Joined: May 2009
Posts: 5,377
Caucasus
Here is how I've edited that function for my old project:
Code:
// accuracy:
var wpn_aim_x = 1; // play with this value
var wpn_aim_y = 1; // play with this value

function bullet_create(VECTOR* vpos, VECTOR* vang, var speed){
	var alive = 16;
	VECTOR pos;
	VECTOR temp;
	VECTOR vel;	
	ANGLE accur;
	vec_set(pos, vpos);
	vec_set(vel, vector(speed, 0, -3));
	vec_set(accur, vector(wpn_aim_x - random(wpn_aim_x * 2), wpn_aim_y - random(wpn_aim_y * 2), 0));
	ang_add(accur, vang);
	vec_rotate(vel, accur);
	while(alive > 0){
		// calculate new position
		vec_set(temp, vel);
		vec_scale(temp, time_step);
		vec_add(temp, pos);
		trace_mode = IGNORE_PASSABLE | USE_POLYGON | SCAN_TEXTURE;
		c_trace(pos, temp, trace_mode); 
		if(trace_hit){
			// check if hit the target:
			if(vec_dist(target, nullvector) > 0){
				// effect for blocks:
				if(hit.entity == NULL){
					
				}	
				else{
					// entity was hit:
				}			
			}
			alive = 0;
		}
		// you may want to shorten vel on impact:
		effect(bullet_effect, 1, pos,vel); 
		// move to new position:
		vec_set(pos, temp); 
		alive -= time_step / 16;
		wait(1);
	}
}

I use it like this:
Code:
bullet_create(muzzle_pos.x, weapon.pan, 400);
// muzzle_pos is the vector where I create muzzle flash effect

Change accuracy of your weapons depending on the player's movement state to make it more realistic laugh


Looking for free stuff?? Take a look here: http://badcom.at.ua
Support me on: https://boosty.to/3rung

Moderated by  adoado, checkbutton, mk_1, Perro 

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