little problem

Posted By: mEnTaL

little problem - 08/19/09 15:45

I have a bullet and a wall. I want when the bullet hit the wall to destroy itself. I tried with EVENT_IMPACT but it detects only moving entities, so the bullet doesn't detect the wall -.-' it's important that the event must be attached to the bullet, not to the wall.
Any suggestions? wink
Posted By: Claus_N

Re: little problem - 08/19/09 16:29

use EVENT_ENTITY and EVENT_BLOCK instead laugh
Posted By: mEnTaL

Re: little problem - 08/19/09 17:13

How to make the bullet destroy itself when its speed=0 ?
(because I didn't manage to make it by EVENT_ENTITY frown I know I am noob with 3dgs grin )
Posted By: MMike

Re: little problem - 08/19/09 17:43

why newbies, instead of learning the basic concept of functions and logic, do want to code more if they dont know how to think. but im afraid this is a IQ gap or something , because that answer is basic logic i think.
but well.
you measure the point where the bullet is emitted.
and while(no impact event)..

wait 1, and calculate the initial bullet position, to the current position.
also, add movement, with c_scan or anything depends on what you want to do.

After the impact the while loop is break, so you know its zero, then explode or remove.. or you use the calculation speed formula.. s="delta"positions/"delta" time. and if zero, trigger removal. with ent_remove i think.

good luck.
Posted By: mEnTaL

Re: little problem - 08/19/09 21:45

action bullet()
{

.............

while(1)
{
c_move(me,vector(40,0,0),nullvector,USE_BOX|IGNORE_MODELS);
c_scan(me.x,360,vector(360,0,200),SCAN_ENTS|IGNORE_FLAG2);
if (result<5) {ent_remove(me);}
wait(1);
}
}

and the engine crashes frown I can't find where is the mistake
Posted By: episch

Re: little problem - 08/19/09 21:59

c_scan(me.x,my.pan,360,vector(360,0,200),SCAN_ENTS|IGNORE_FLAG2);

the my.pan in the c_sacn was the mistake.
Posted By: episch

Re: little problem - 08/19/09 22:05

c_scan(me.x,my.pan,360,vector(360,0,200),SCAN_ENTS|IGNORE_FLAG2);

the my.pan in the c_sacn was the mistake.
but you do a realy complicatet way. i made this much easier.

try this witch EVENT_BLOCK for the wall
the wen the event is trigerd make the bullet INVISIBLE and remove the bullet. like this:

Code:
function wall(){
set(my,INVISIBLE);
set(my,PASSABLE);
wait(4);
ent_remove(me);
}

action bullet(){
my.push = 10;
my.emask |= (EVENT_BLOCK|EVENT_IMPACT|EVENT_ENTITY);
my.event = wall;
while(1){
c_move(my,vector(20,0,0),nullvector,GLIDE,IGNORE_FLAG2);
wait(1);
}}


the EVENT_IMPACT trigger only by entitys with lower push
the same with the EVENT_ENTITY.
i hope i can help you with this.
greets episch
Posted By: mEnTaL

Re: little problem - 08/19/09 22:41

Originally Posted By: episch
c_scan(me.x,my.pan,vector(360,0,200),SCAN_ENTS|IGNORE_FLAG2);

the my.pan in the c_sacn was the mistake.


actulay my.pan is not the mistake, it crashes again frown


your second way works, but EVENT_BLOCK is for block primitives only.
My walls are models (Entities)
Posted By: MMike

Re: little problem - 08/19/09 22:43

i just dont understand why the bullet is action bullet and not function bullet?
since this bullet is runtime created it should be function..
on the ent_create process pass the function bullet right.

Also making that while loop, and then the event removing the entity while in the while loop will certain crash!! no? i think it should be

while(me) and not while (1);
Posted By: mEnTaL

Re: little problem - 08/19/09 23:35

it's ok now, but I can't understand only ome thing: why the bullet gets destroyed when it is created. It seems that it detects the player and the gun entities, but they have Flag2 set, and the c_scan functions has IGNORE_FLAG2, I added and IGNORE_ME and the same thing happens.
Posted By: episch

Re: little problem - 08/20/09 09:06

so you mus spawn the bullet a litter front the gun with vec_vor vertex.
so open you gun model in MED look witch vertex are at the front of the gun
example = put this in the action for the gun :
vec_for_vertex(temp,my,xx) xx is the vertex from the gun
temp.x +=5;
ent_create("bullet.mdl",temp,bullet);

and set the FLAG2 tag to the gun and the player
Posted By: mEnTaL

Re: little problem - 08/20/09 10:44

i know that, my bullet is created this way, but it doesn't help.
Posted By: MMike

Re: little problem - 08/20/09 11:49

try this:
right on the first line of wall function:

if(is(you,FLAG2)==1){return;}

by the way your gun, and player, must have set(my,FLAG2); to work

Posted By: mEnTaL

Re: little problem - 08/20/09 14:06

function bullet()
{
.........

while(me)
{
c_move(me,vector(40,0,0),nullvector,USE_BOX|IGNORE_MODELS);
c_scan(me.x,me.pan,vector(360,0,200),SCAN_ENTS|IGNORE_FLAG2|IGNORE_ME);
if (result<5)
{
if(is(you,FLAG2)==1){return;}
ent_remove(me);
}
wait(1);
}
}

and also the player and the gun have Flag2 set, but the engine crashes. Can you correct it if you find mistake in the code pls
Posted By: Pappenheimer

Re: little problem - 08/20/09 14:45

You probably have to assure that the 'you' isn't empty.

Other suggestions:
- you could start the scan a few moments later, when the bullet already left the gun.
- Did you try IGNORE_YOU? Although, it has to reset after leaving the gun.
- you could scan from a position ahead the bullet:
vec_for_angle(temp, my.pan);//Get a 'direction' from the angle
//Now, when the position is one quant ahead the bullet, scale the vector/direction to get the position a few quants more ahead, let's say 10:
vec_scale(temp, 10);
Posted By: mEnTaL

Re: little problem - 08/20/09 16:23

I tried all the suggestions:
I made check if(you!=NULL) to do the rest
I made the bullet start the scanning 10 frames after it's created
I put IGNORE_YOU
i made the bullet scan 10 quants ahead it
but maybe I miss something or do something wrong cuz the engine crashes again.
Can you post here the shortest and fastest code for moving entity which destroys itself when hit static entity. Thx laugh
Posted By: MMike

Re: little problem - 08/20/09 20:04

well the crash.. is wird.. give us the acklog, maybe thats better, to check the error.. and where is the actual crash, are sure its from those functions or are others?

Also.after the bullet is created you must put an wait(1); after..
Posted By: mEnTaL

Re: little problem - 08/22/09 22:58

I use this collision code:

function remove_bullets();

function bullet()
{
my.emask|=ENABLE_IMPACT;
my.emask|=ENABLE_ENTITY;
my.emask|=ENABLE_BLOCK;
my.event = remove_bullets;
while(1)
{
c_move(me,vector(40,0,0),nullvector,USE_BOX|IGNORE_MODELS);
wait(1);
}
}

function remove_bullets() // this function runs when the bullet collides with something
{
wait (1); // wait a frame to be sure (don't trigger engine warnings)
ent_remove (my); // and then remove the bullet
}

The collision detection definitely works, but can you just tell me how to make the bullet don't detect the gun and the player models in this case
© 2024 lite-C Forums