1 registered members (monarch),
1,259
guests, and 5
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
3rd person, adjusting bullet to crosshair
#318505
04/08/10 02:09
04/08/10 02:09
|
Joined: Jul 2009
Posts: 85
Altarius
OP
Junior Member
|
OP
Junior Member
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]
#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
User
|
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 ^^
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
Altarius
OP
Junior Member
|
OP
Junior Member
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 laugh](/ubb7/images/graemlins/default_dark/laugh.gif)
|
|
|
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
User
|
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
Phonech
Newbie
|
Newbie
Joined: Feb 2009
Posts: 38
Germany
|
I guess it would look like this...
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.
|
|
|
|