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
3rd person, adjusting bullet to crosshair #318505
04/08/10 02:09
04/08/10 02:09
Joined: Jul 2009
Posts: 85
A
Altarius Offline OP
Junior Member
Altarius  Offline OP
Junior Member
A

Joined: Jul 2009
Posts: 85
Hi,

I cant figure out how to adjust my bullet trajectory for hit at the middle of my crosshair whit a 3rd person camera...

i use a bullet code like this one.. anyone can help?

function fire_bullets()
{
VECTOR temp;
proc_kill(4); // don't allow more than 1 copy of this function to run
while (mouse_left) // this loop runs for as long as the left mouse button is pressed
{
vec_for_vertex (temp.x, weapon1, 54); // get the coordinates for the bullets' origin
// create the bullet at camera's position and attach it the "move_bullets" function
ent_create ("bullet.mdl", temp.x, move_bullets);
wait (-0.07); // fire 7 bullets per second (2 * 0.07 * 7 = 1 second)
wait (-0.07);
}
}

function move_bullets()
{
VECTOR bullet_speed; // stores the speed of the bullet
//ang_for_bone(bone1_angle, weapon1, "bone1");

my.skill30 = 1; // I'm a bullet
my.emask |= (ENABLE_IMPACT | ENABLE_ENTITY | ENABLE_BLOCK);
my.event = remove_bullets; // when it collides with something, its event function (remove_bullets) will run
//my.pan = camera.pan; // the bullet has the same pan
my.pan = camera.pan; // rotate gun by hand angle
my.tilt = camera.tilt; // and tilt with the camera
bullet_speed.x = 100 * time_step; // adjust the speed of the bullet here
bullet_speed.y = 0/*random(0.5)-0.5*/; // the bullet doesn't move sideways
bullet_speed.z = 0/*random(0.5)-0.5*/; // then don't allow the gravity to have its ways with the bullet
while (my) // this loop will run for as long as the bullet exists (it isn't "null")
{
// move the bullet ignoring the passable entities and store the result in distance_covered
c_move (my, bullet_speed, nullvector, IGNORE_PASSABLE);
wait (1);
}
}

I a

Re: 3rd person, adjusting bullet to crosshair [Re: Altarius] #318510
04/08/10 03:56
04/08/10 03:56
Joined: Mar 2009
Posts: 88
Walori Offline
Junior Member
Walori  Offline
Junior Member

Joined: Mar 2009
Posts: 88
one way would be vec_for_screen. And put the bullet face this vector when it's created. Then the bullet will hit the crosshair at the distance you gave the vector in vec_for_screen.

Re: 3rd person, adjusting bullet to crosshair [Re: Walori] #318577
04/08/10 15:29
04/08/10 15:29
Joined: Dec 2008
Posts: 605
47°19'02.40" N 8°32'54.67" E...
hopfel Offline
User
hopfel  Offline
User

Joined: Dec 2008
Posts: 605
47°19'02.40" N 8°32'54.67" E...
You can calculate the vector-position with c_trace from the camera away (dark-red line) and then angle the gun and the bullet on this target-position.
I made a little image of it:
http://www.haeschen.ch/hopfel/bilder/schiessbeispiel.bmp
If you want I can look for my code I made 3-4 months ago for my 3th person shooter, but it's much better for you, if you elaborate it yourself laugh


Hilf mir, dir zu helfen!
Re: 3rd person, adjusting bullet to crosshair [Re: hopfel] #318811
04/10/10 00:51
04/10/10 00:51
Joined: Jul 2009
Posts: 85
A
Altarius Offline OP
Junior Member
Altarius  Offline OP
Junior Member
A

Joined: Jul 2009
Posts: 85
thx for ur answer guys...

But i still a little lost whit the code... can u show me ur code whit the c_trace plz.

Re: 3rd person, adjusting bullet to crosshair [Re: Altarius] #318838
04/10/10 10:06
04/10/10 10:06
Joined: Dec 2008
Posts: 605
47°19'02.40" N 8°32'54.67" E...
hopfel Offline
User
hopfel  Offline
User

Joined: Dec 2008
Posts: 605
47°19'02.40" N 8°32'54.67" E...
Ok, I'll write it in here for you ^^

Code:
VECTOR targetpos;

function bullet()
{
VECTOR ziel;

vec_set(ziel,targetpos);	
vec_sub(ziel,my.x);
vec_to_angle(my.pan,ziel); //bullet looks at the target :)

while(my)
{
c_move(my,vector(30*time_step,0,0),nullvector,IGNORE_SPRITES + IGNORE_PASSABLE + IGNORE_ME); //and shoots

}}


function player()
{
while(my)
{

vec_set(my.skill7,vector(10000,0,0));
vec_rotate(my.skill7,camera.pan);
vec_add(my.skill7,camera.x);
my.skill6 = c_trace(camera.x,my.skill7,IGNORE_SPRITES + IGNORE_PASSABLE);
if(my.skill6==0)
vec_set(my.skill10,vector(10000,0,0));
else
vec_set(my.skill10,vector(my.skill6,0,0));
vec_rotate(my.skill10,camera.pan);
vec_add(my.skill10,camera.x); //my.skill10 is now the vector from the target

vec_set(targetpos,my.skill10); //targetpos is now the vector from the target

if(key_space) //if you press the space key
ent_create("bullet.mdl",my.x,bullet); //create bullet

wait(1);
}}



It's not tested (I changed it a bit for a better appreciation)
Hope you can work with it ^^


Hilf mir, dir zu helfen!
Re: 3rd person, adjusting bullet to crosshair [Re: hopfel] #318885
04/10/10 16:46
04/10/10 16:46
Joined: Jul 2009
Posts: 85
A
Altarius Offline OP
Junior Member
Altarius  Offline OP
Junior Member
A

Joined: Jul 2009
Posts: 85
Thx for the code that work great, except for one thing...

Supposed i want to shoot a target in movement, i need to place my shot i little before it, so now the c_trace aim far away and the shot are not accurate.Maybe the vec_for_screen are better for this?

I u have the time... can u show me a vec_for_screen exemple for a 3rd camera where the bullet start at the muzzle vertex of my gun (vec_for_vertex (temp.x, weapon1, 54);)

Thx for the time u spend to help me i appreciate. laugh

Re: 3rd person, adjusting bullet to crosshair [Re: Altarius] #318939
04/10/10 21:28
04/10/10 21:28
Joined: Dec 2008
Posts: 605
47°19'02.40" N 8°32'54.67" E...
hopfel Offline
User
hopfel  Offline
User

Joined: Dec 2008
Posts: 605
47°19'02.40" N 8°32'54.67" E...
I'll say, my example has the same effect if you do it with vec_for_screen. (It's just a bit better to edit and adjust for your game, if you use my example ^^)
And I can't give you an example for vec_for_screen because I didn't work with it before, I just know, what it does ^^
Btw. there is no really good solution for your problem, if you want, the bullet makes damage by hitting the target.
You can also calculate, if a Entity is in your eyepiece or not, but then, you wouldn't see any shots.

If you want to make an 3rd camera shooter, I don't see another way as my example. Sorry...


Hilf mir, dir zu helfen!
Re: 3rd person, adjusting bullet to crosshair [Re: Altarius] #318979
04/11/10 10:55
04/11/10 10:55
Joined: Feb 2009
Posts: 38
Germany
P
Phonech Offline
Newbie
Phonech  Offline
Newbie
P

Joined: Feb 2009
Posts: 38
Germany
I guess it would look like this...
Code:
VECTOR t_pos1,t_pos2;
ANGLE tempA;
var bullet_fired;

function trace_collision() //<-in player's while loop
{
	t_pos1.x = screen_size.x/2;
	t_pos1.y = screen_size.y/2;
	t_pos1.z = 0;
	vec_for_screen (t_pos1,camera);
	t_pos2.x = screen_size.x/2;
	t_pos2.y = screen_size.y/2;
	t_pos2.z = 200000; 
	vec_for_screen (t_pos2,camera);
	
	if (c_trace(t_pos1.x,t_pos2.x, IGNORE_ME | IGNORE_PASSABLE | IGNORE_YOU) > 0)
	{
		vec_set(trace_coords,target);
	}	
}

function move_parrows() //some AUM code right here
{
	vec_set(tempA,trace_coords);
	vec_sub(tempA,my.x);
	vec_to_angle(my.pan,tempA);
	
	while(1) 
	{
		if (vec_dist(my.x, player.x) > 70) // the bullet has moved away from the player?
					reset(my, PASSABLE); // then reset its passable flag (it can't collide with player's ship anymore)
		c_move(my, vector(75 * time_step,0,0), nullvector, IGNORE_PASSABLE | IGNORE_ME ); // 75 gives player's bullets' movement speed	
		wait (1);
	}
}

function handle_weapon()//<-in player's while loop
{
	if(!mouse_left) bullet_fired = 1;
	while(mouse_left)
	{	
		bullet_fired = 0;
		wait(1);
	}	
	if(!bullet_fired)
	{
		vec_for_vertex (temp.x, weapon1, 54);
		bullet = ent_create(bullet_mdl,temp.x,move_bullets);
		bullet_fired = 1;
	}
}


I'm not sure whether it works, just try it out^^

Last edited by Phonech; 04/11/10 11:02.

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