|
7 registered members (fairtrader, Quad, miwok, Martin_HH, AndrewAMD, alibaba, dpn),
581
guests, and 0
spiders. |
|
Key:
Admin,
Global Mod,
Mod
|
|
|
Re: bullet holes
[Re: vartan_s]
#74985
05/21/06 14:54
05/21/06 14:54
|
Joined: Jun 2004
Posts: 2,234 Wisconsin USA
FoxHound
Expert
|
Expert
Joined: Jun 2004
Posts: 2,234
Wisconsin USA
|
You might need to give us the code you are working on so we can see the problem. Ideas at this point
switch to c_move, ent_move will go bye bye soon enough so best to swap now. This may not be the problem but it might be.
Look up "normal" in the manual, there was a code there that showed how to set normals.
--------------------- There is no signature here.
QUIT LOOKING FOR ONE!
|
|
|
Re: bullet holes
[Re: FoxHound]
#74986
05/27/06 14:27
05/27/06 14:27
|
Joined: Sep 2003
Posts: 4,959 US
Grimber
Expert
|
Expert
Joined: Sep 2003
Posts: 4,959
US
|
as Fox said use c-Move ( unless your an a5 user)
im not going to write the code ( because ive done elsewhere thats avaible) but ill cover the basics of bullet holes
people tend to perfer 1 of 2 general methods of handing 'shooting' 1. ) a trace to 'simulate' a shot 2. ) moving a model entity as a bullet
for the first method its very simple. do a c-trace from the gun barrel x/y/z out some arbitrary distance in the direction vector of the gun. trace, if it hits a wall or object sets, the pre-defined TARGET vector setting the x/y/z location where it intersected something and sets the NORMAL vector to the direction vector of that surface.
then create your bullethole entity at TARGET ( make the entity passable)and align its angles to the NORMAL
for number 2 its a little more work
first off for a bullet model don;t use 'glide' in its move mode. you don't want the bullets slidding along your walls and making it even harder to place bullet holes that way
of course you also need event handling for your model so when it does impact something it triggersn an even fucntion so you can handle that.
now when the model moves ( any model uder movment of ent_move c_move) it will try to move the entire length of its direction vector for each frame. with ent_move soemtimes when the event is triggered and when your event function actualy registers the collision can be the differnace of 1 entire frame ( thus is why in older versions of the engine (prior to 6.22 i think) you needed a wait(1) usualy as your first line of an event function to be sure the collsion flag (event_type) is properly set.
so.. you have your bullet its moving hits a block, triggers your event function. first think you would think is to ent_create my bullet hole sprite at my bullets x/y/z. yes and no.
remember your MODEL hit the surface, but your models x/y/z is not the actual collision point ( the point that bullet hits wall). so your sprite is out away from the wall.
ok so i change my model so the models origin point as at the tip of the bullet to hit the wall. hmm that still doesn't work, in fact its further out from the wall. moving mdoels use an eliptical hull ( or a rectangular hull with ent_move) centered on its origin out to roughly its furthest vertex ( poly pression should only be used on NON moving entitys). So your better off with your model as before. origin centered in the mesh.
here is what you do.
event function called. trace from bullet x/y/z to an arbitrary distance in the direction of your bullets movment direction vector. trace then will return the TARGET and NORMAL you need to set the bullethole sprite.
if you are using the BOUNCE to bounce your bullets off walls, then you have to add the additional calculation of which way is my bullet facing in comparison to the wall ( bullet direction vs wall normal) then trace back to the wall as above)
with the NORMAL that is a direction vector, you need to convert it to pan/tilt angles and then orintate the sprite. rememebr to ent creat the sprite and make it passable right away. 1 its hard to set it right when its collsion is on, also if anotehr bullet hits a bullethole sprite the bullet just stops on the sprite which is covering the wall surface as for code plenty of examples of doing this can be found check out resource site and the tutorials
|
|
|
Re: bullet holes
[Re: vartan_s]
#74988
05/28/06 06:09
05/28/06 06:09
|
Joined: Sep 2003
Posts: 4,959 US
Grimber
Expert
|
Expert
Joined: Sep 2003
Posts: 4,959
US
|
the trace should be done in the action script of your ent_created bullet hole sprite entity. you need to store the direction vector to the wall into a temporary vector, then the bullethole action script reads/uses that vector for the direction to trace TO
( best is to take the vector and magnify it with vec_normalize to get your trace end point)
example lets say my bullets don;t bounce off walls, so I can just go ahead and use my bullets relvector movment value for the trace
define move_dist ,skill40; // so ill use skill40 41 and 42 for my move vector action bullet_move { //... vec_set(my.move_dist,vector(10*time,0,0)); // or as long as I know skill41 and 42 are never set valeus i could just do // my.move_dist = 10*time; but the above line makes SURE and not assumes c_move(my,my.move_dist, .....
action bullethole { my.passable = on; // because at the time this entity is created YOU pointer will point back to the bullet entity so we can sue that to grab our movment vector IF we do it right away
vec_set(my.move_dist,YOU.move_dist); // the movment direction vector backed up
vec_normalize(my.move_dist,10); // here i just increased the length of teh vector *10 //now I just do the trace my.skill10 = c_trace(my.x,my.move_dist,IGNORE_ME+IGNORE_YOU); // the ignore you is important too. else your still existing bullet entity will stop the trace soon as it starts. if(my.skill10 >0) // trace hit something { my.oriented = on; // look up these to line sin manual if you don't know them my.facing = off; vec_set(my.x,TARGET); vec_to_angle(my.pan,normal); } else // no surface to attach to so remove me from the world { remove(me); }
and so forth. there smore to it depending on your intended usage but that should get you in the ballpark of basic sticking sprites to a surface.
|
|
|
Re: bullet holes
[Re: Grimber]
#74992
05/29/06 17:34
05/29/06 17:34
|
Joined: Apr 2006
Posts: 265
vartan_s
OP
Member
|
OP
Member
Joined: Apr 2006
Posts: 265
|
What I mean is, I don't want to change the way I work with my variables. I have a variable called bullet_speed, I set this to the bullet's skill5, then send the bullet. I want it to continue like this. Another thing: I don't use actions for bullets, I use 3 functions: shoot_bullet remove_bullet bullet_hole the shoot bullet enables event block, if it hits, goes to remove_bullet, which then creates a hole and gives it the function bullet_hole. It doesn't work completely anyway, no matter how much I change. The bullets holes are pasted perfectly on walls, but are a little off, and sometimes on the wrong wall (I shoot at the ceiling and it goes onto the beside wall!)
Two more things, the bullet is perfectly on the wall, so it sometimes gets cuts in it (we can see through it to the wall). And sometimes the bullet appears off the edge off the wall; part on and part off.
If you could solve these, I'd be really grateful. Thanks in advance.
|
|
|
Re: bullet holes
[Re: vartan_s]
#74993
05/30/06 06:41
05/30/06 06:41
|
Joined: Sep 2003
Posts: 4,959 US
Grimber
Expert
|
Expert
Joined: Sep 2003
Posts: 4,959
US
|
your entire bullet handling script shouldn;t be more complex than this and you should not manitpulate the existance of an entity ( create or remove) from an event function or a function called by an event function example: Code:
function bullet_hit() { if(EVENT_TYPE == EVENT_BLOCK) { my.flag8 = on; } }
action move_bullet { // parameters set here my.enable_block = on; my.event = bullet_hit; while (my.flag1 != 1) { // movment stuff here if (my.flag8 == 1) { // create bullet hole sprite here my.flag1 = 1; } wait(1); } ent_remove(me); }
for a litte more complex one. here is a cut and paste of teh bullet script i did in part of the FPS doc i wrote (on ackenext site ). It's a little old now, but still you can pick it part for the structure. its set up the same way as above, just more to it because it handles multiple types of guns what is critical here is TIMING notice in the bullet_hole script i use NORMAL right away which is a temporary vector used by the engine. this Only works because i KNOW that normal is being set JUST before by the EVENT_BLOCK handling. things this close in timing you have to be right on top of the flow of your script. timing,speed, guesswork or close enough doesn't work in these cases. Code:
action bullet_hole { // just parameters set up here my.scale_x = .5; my.scale_y = .5; my.scale_z = .5; my.oriented = on; my.alpha = 100; my.flare = on; my.overlay = on; my.transparent = on; my.passable = on; vec_to_angle(my.pan, NORMAL); Vec_set(temp,Normal); // copy the normal direction vector to temp Vec_inverse(temp); // inverts the direction vector Vec_to_angle(temp2,temp); // I convert temp direction angle to a pan/tilt angle and store it temp2 vec_set(temp,vector(100,0,0)); vec_rotate(temp,temp2); vec_add (temp,my.x); trace_mode = ignore_me+ignore_passable+ignore_models + ignore_maps + ignore_sprites + ignore_push; trace(my.x,temp); vec_set(my.x,TARGET);
sleep(5); while (my.alpha > 0) { my.alpha -= .25*TIME; wait(1); } ent_remove(me); }
function bullet_event() { if(EVENT_TYPE == event_block) { my.flag3 = on; ent_playsound(me,b_bounce,60); if (my.flag2 == ON) // bounce { vec_to_angle (my.pan, bounce); // bounce direction } else { my.flag1 = ON; } } if(EVENT_TYPE == event_entity && YOU.flag8 == ON) { if (YOU.armor >= bullet_damage[my.skill100]) { YOU.armor -= bullet_damage[my.skill100]; my.flag1 = ON; } else { YOU.health -= bullet_damage[my.skill100]-YOU.armor; YOU.armor = 0; my.flag1 = ON; } } }
action bullet_move { turn_towards_target(); my.enable_block = ON; my.enable_entity = ON; my.event = bullet_event; my.flag1 = OFF; my.flag2 = bullet_bounce[current_weapon]; my.skill100 = current_weapon; if (my.skill100 == 3) { vec_set(my.skill40,my.x); // set the my.x location vector to skills 40,41,42 vec_set(temp.x,vector(1,0,0)); // vector length of 1 quant vec_rotate(temp.x,my.pan); // temp is now a vector of length 1 quant in direction bullet goes vec_set(temp2.x,vector(20,0,0)); // set temp2 as a vector length of 20 quants vec_rotate(temp2.x,my.pan); // rotate it by bullets pan/tilt angles my.skill50 = 1; while (my.skill50 < 40) { effect(laser_part,1,my.skill40,temp2); vec_add(my.skill40,temp.x); my.skill50 += 1; } } while (my.skill20 < bullet_ranges[my.skill100] && my.flag1 == OFF) { move_mode = IGNORE_YOU + IGNORE_PASSABLE + IGNORE_PUSH; my.skill20+= ent_move(vector(bullet_speeds[my.skill100],0,0),nullvector); if (my.flag3 == on) { ent_create(bullet_holes.string[my.skill100],my.x,bullet_hole); my.flag3 = off; } wait(1); } ent_remove(me); }
some of teh sissues yoru having is in timing. the calling and executing of multiple functions. 1-2 frames can pass between the time some data is set for a condition and when the function actually occurs, by then your data can be now incorrect. such as your bulletholes not exactly on the wall or they are touching but not flush aganst the wall or not even ON the right wall. reading the right data but at the wrong time if your getting ones that are on the wall as should be but they are shredded in appearance. then those are right. use the my.decal flag on the sprite
|
|
|
Moderated by mk_1, Perro, rayp, Realspawn, Rei_Ayanami, rvL_eXile, Spirit, Superku, Tobias, TSG_Torsten, VeT
|