|
bullets
#247321
01/20/09 06:27
01/20/09 06:27
|
Joined: Oct 2008
Posts: 67
pewpew
OP
Junior Member
|
OP
Junior Member
Joined: Oct 2008
Posts: 67
|
i've followed the help section but i cant seem to get the bullets i fire from my vehicle to disappear after they hit an object (like a wall in a level etc.)
they just freeze on the object. i am using c_move to propell the bullet from the gun.
how do you detect a collision and destroy the bullet?
HURRR DERP DERP DEERRPP HURR
|
|
|
Re: bullets
[Re: pewpew]
#247336
01/20/09 09:24
01/20/09 09:24
|
Joined: Jul 2002
Posts: 4,436 Germany, Luebeck
Xarthor
Expert
|
Expert
Joined: Jul 2002
Posts: 4,436
Germany, Luebeck
|
use a skill (or flag) of the bullet to check if its alive or not. In the event function set this skill (or flag) to "dead". Furthermore you use this skill (or flag) as condition for the while loop of it, which is then skipped when the bullet is "dead" and after the while loop you remove the bullet. lite-C Example using a skill:
#define health skill1
function bullet_event()
{
if(event_type == EVENT_BLOCK || event_type == EVENT_ENTITY)
{
my.health = 0;
}
}
action bullet_act()
{
my.health = 1;
while(my.health)
{
// do the c_move stuff in here
}
wait(1);
ent_remove(me);
}
note: Not tested code!
|
|
|
Re: bullets
[Re: Xarthor]
#247339
01/20/09 09:51
01/20/09 09:51
|
Joined: Oct 2008
Posts: 67
pewpew
OP
Junior Member
|
OP
Junior Member
Joined: Oct 2008
Posts: 67
|
//fire primary weapon
action game_fire_primary()
{
e_bullet = ent_create("models\\bullet1.mdl", tank_turret.x, game_fire_bullet);
vec_set(e_bullet.pan, tank_turret.pan);
}
//bullet behaviour
action game_fire_bullet()
{
my.skill1 = 1;
while(my.skill1)
{
c_move(me, vector(0,40,0), nullvector, IGNORE_FLAG2);
game_bullet_collide();
wait(1);
}
wait(1);
ent_remove(me);
}
//bullet destruction
function game_bullet_collide()
{
if(event_type == EVENT_BLOCK || event_type == EVENT_ENTITY)
{
me.skill1 = 0;
draw_text("collision", settings.screen.x / 2, settings.screen.y /2, vector(255,0,0));
}
}
it doesnt seem to work? the bullet just seems to stop on the wall or entities....? im not sure what im doing wrong 
HURRR DERP DERP DEERRPP HURR
|
|
|
Re: bullets
[Re: pewpew]
#247342
01/20/09 10:16
01/20/09 10:16
|
Joined: Jul 2007
Posts: 959 nl
flits
User
|
User
Joined: Jul 2007
Posts: 959
nl
|
add my.emask |= (ENABLE_BLOCK | ENABLE_ENTITY); my.event = game_bullet_collide; to action game_fire_bullet
dam i forgot the event
Last edited by flits; 01/20/09 10:20.
"empty"
|
|
|
Re: bullets
[Re: pewpew]
#247343
01/20/09 10:18
01/20/09 10:18
|
Joined: Jul 2002
Posts: 4,436 Germany, Luebeck
Xarthor
Expert
|
Expert
Joined: Jul 2002
Posts: 4,436
Germany, Luebeck
|
uhps I forgot that you need to set the events.
//bullet destruction
function game_bullet_collide()
{
if(event_type == EVENT_BLOCK || event_type == EVENT_ENTITY)
{
me.skill1 = 0;
}
}
//bullet behaviour
action game_fire_bullet()
{
my.skill1 = 1;
my.emask |= (ENABLE_BLOCK | ENABLE_ENTITY);
my.event = game_bullet_collide;
while(my.skill1)
{
c_move(me, vector(0,40,0), nullvector, IGNORE_FLAG2);
wait(1);
}
wait(1);
ent_remove(me);
}
you should also multiply your movement speed with time_step to get frame-rate independent movement
|
|
|
Re: bullets
[Re: Xarthor]
#247347
01/20/09 11:25
01/20/09 11:25
|
Joined: Oct 2008
Posts: 67
pewpew
OP
Junior Member
|
OP
Junior Member
Joined: Oct 2008
Posts: 67
|
perfect thanks guys 
HURRR DERP DERP DEERRPP HURR
|
|
|
Moderated by mk_1, Perro, rayp, Realspawn, Rei_Ayanami, rvL_eXile, Spirit, Superku, Tobias, TSG_Torsten, VeT
|