|
Re: c_trace and shooting projectile help
[Re: immolat3]
#168147
11/20/07 06:26
11/20/07 06:26
|
Joined: Nov 2007
Posts: 73
immolat3
OP
Junior Member
|
OP
Junior Member
Joined: Nov 2007
Posts: 73
|
|
|
|
Re: c_trace and shooting projectile help
[Re: immolat3]
#168148
11/20/07 15:00
11/20/07 15:00
|
Joined: Oct 2004
Posts: 4,134 Netherlands
Joozey
Expert
|
Expert
Joined: Oct 2004
Posts: 4,134
Netherlands
|
make an entity and move it in the right direction. To do this, make a new function called "iKillYou()" and attach it to the entity you created. In this function, you put the entity at the start position of the c_trace. Then, using vec_to_angle and the direction between start and endpoint of the c_trace, turn the model towards the end position of the c_trace. Your bullet is now created and faces the target. The following depends on how you want the bullet to function. Should it hit obstacles that come in the way while moving in the path of the bullet, or is it just a straight line reaching the c_trace target whatever is inbetween? The first is somewhat complicated, the latter is the quickest. For shooting at a target where the bullet will always reach the target of c_trace: Code:
//psuedo code function iKillYou while (target != reached) { bullet.angle = vec_to_angle(dirVecToTarget) //bullet faces target of the c_trace (dirVecToTarget = direction from start to end of c_trace) bullet.position += vec_normalize (dirVecToTarget, speed) //now move forward by adding the direction vector, multiplied by the speed of the bullet }
EDIT: as a side note, you can pass the direction vector and player angles to the function immediately as well of course, which spares some calculations with vec_for_angle and vec_to_angle. Probably a better way as you need less calculations and code. Hope that will help you enough to find out yourself.
Last edited by Joozey; 11/20/07 15:04.
Click and join the 3dgs irc community! Room: #3dgs
|
|
|
Re: c_trace and shooting projectile help
[Re: immolat3]
#168151
11/20/07 23:54
11/20/07 23:54
|
Joined: Nov 2007
Posts: 73
immolat3
OP
Junior Member
|
OP
Junior Member
Joined: Nov 2007
Posts: 73
|
Code:
// Fire Gun Function function PewPew() { var theTarget; bullet = "bullet.mdl"; vec_set(theTarget.x, vector(10000, 0, 0)); // shoots 10000 quants vec_rotate(theTarget.x, camera.pan); // shoots in the direction of the player (cameras pan, b/c 3rd person) c_trace(my.x, theTarget.x, ignore_me + scan_texture | ignore_passable | use_aabb );
if(str_cmpi(tex_name, "TESTBOSS.MDL") == 1 && getEnergy() >= shootEnergy) { doDamage(shootDmg); subtractEnergy(shootEnergy); snd_play(laserPew, 100, 0); } if(getEnergy() < shootEnergy) { snd_play(laserEmpty, 100, 0); subtractEnergy(0); } else { snd_play(laserNoHit, 100, 0); subtractEnergy(shootEnergy); } snd_stop(laserPew); snd_stop(laserEmpty); snd_stop(laserNoHit); }
Any ideas on how to make this shoot bullet.mdl?
|
|
|
Re: c_trace and shooting projectile help
[Re: immolat3]
#168152
11/21/07 11:09
11/21/07 11:09
|
Joined: Oct 2004
Posts: 4,134 Netherlands
Joozey
Expert
|
Expert
Joined: Oct 2004
Posts: 4,134
Netherlands
|
I don't see where you create the bullet. When you get stuck, try set the bullet's passable flag on.
Last edited by Joozey; 11/21/07 11:10.
Click and join the 3dgs irc community! Room: #3dgs
|
|
|
Re: c_trace and shooting projectile help
[Re: immolat3]
#168154
11/21/07 16:58
11/21/07 16:58
|
Joined: Nov 2007
Posts: 73
immolat3
OP
Junior Member
|
OP
Junior Member
Joined: Nov 2007
Posts: 73
|
Code:
entity* bullet;
action bulletFly { my.passable = on; c_move(me, nullvector, nullvector, ignore_me); }
// Fire Gun Function function PewPew() { var theTarget; vec_set(theTarget.x, vector(10000, 0, 0)); // shoots 10000 quants vec_rotate(theTarget.x, camera.pan); // shoots in the direction of the player (cameras pan, b/c 3rd person) c_trace(my.x, theTarget.x, ignore_me + scan_texture | ignore_passable | use_aabb ); ent_createlocal("bullet.mdl", plBiped01_entity.x, bulletFly);
if(str_cmpi(tex_name, "TESTBOSS.MDL") == 1 && getEnergy() >= shootEnergy) { doDamage(shootDmg); subtractEnergy(shootEnergy); snd_play(laserPew, 100, 0); } if(getEnergy() < shootEnergy) { snd_play(laserEmpty, 100, 0); subtractEnergy(0); } else { snd_play(laserNoHit, 100, 0); subtractEnergy(shootEnergy); } snd_stop(laserPew); snd_stop(laserEmpty); snd_stop(laserNoHit); } right now it creates the bullet.mdl when i fire, but it just kind of stays there.
|
|
|
Re: c_trace and shooting projectile help
[Re: immolat3]
#168155
11/21/07 17:01
11/21/07 17:01
|
Joined: Oct 2004
Posts: 4,134 Netherlands
Joozey
Expert
|
Expert
Joined: Oct 2004
Posts: 4,134
Netherlands
|
Because it only will go through c_move once now, you need to put it in a while loop while (me) {}. When the bullet is removed, 'me' will return false and the while loop will automaticly stop to prevent empty pointer errors. EDIT: And you need to replace the first nullvector with vector (speed, 0, 0) EDIT2: Ánd if your game is not multiplayer, you can just use ent_create isntead of ent_createlocal
Last edited by Joozey; 11/21/07 17:03.
Click and join the 3dgs irc community! Room: #3dgs
|
|
|
|