Gamestudio Links
Zorro Links
Newest Posts
Zorro Beta 2.61: PyTorch
by jcl. 06/10/24 14:42
New FXCM FIX Plugin
by flink. 06/04/24 07:30
AlpacaZorroPlugin v1.3.0 Released
by kzhao. 05/22/24 13:41
Free Live Data for Zorro with Paper Trading?
by AbrahamR. 05/18/24 13:28
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
1 registered members (AndrewAMD), 1,577 guests, and 7 spiders.
Key: Admin, Global Mod, Mod
Newest Members
AemStones, LucasJoshua, Baklazhan, Hanky27, firatv
19058 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 5 1 2 3 4 5
Pointer troubles: Need Help #267678
05/25/09 20:21
05/25/09 20:21
Joined: May 2009
Posts: 258
Chicago
J
Jaeger Offline OP
Member
Jaeger  Offline OP
Member
J

Joined: May 2009
Posts: 258
Chicago
I've been having a little trouble with pointers for my bullets. For some reason, sometimes the bullet's impact, entity, or block collision events don't register. And there will be many of them lying around on the ground. So I came up with the idea to use phent_getvelocity to determine whether or not they are still in flight, and if not, remove them.

However, when this occurs, and one is removed, it creates an "empty pointer" error message. I tried giving a specific pointer to each type of bullet, but that turned out to cause a whole bunch of unnecessary trouble. Now they just have an action, that tells them what to do. So how can I create a certain lifespan for bullets, and/or check their speed, and remove a particular one who meets the "dead bullet" criteria, without causing an empty pointer error?

And if you know, any idea why some of them don't run their collision event?

Re: Pointer troubles: Need Help [Re: Jaeger] #267680
05/25/09 20:35
05/25/09 20:35
Joined: May 2009
Posts: 258
Chicago
J
Jaeger Offline OP
Member
Jaeger  Offline OP
Member
J

Joined: May 2009
Posts: 258
Chicago
Ok, well I figured out how to give every bullet a max lifespan of 10secs. It successfully removed all bullets after 10secs without any errors.

Now I have to figure out a way to make the tracer/smoke effect stop for bullets that don't run their impact/entity/ or block event. Any ideas?

Really would be nice to figure out why some don't do it. Could it be that the bullets strike the inside of my tank's bounding box before they are launched away? And that disables the event? smirk

Re: Pointer troubles: Need Help [Re: Jaeger] #267685
05/25/09 21:51
05/25/09 21:51
Joined: Oct 2004
Posts: 1,655
T
testDummy Offline
Serious User
testDummy  Offline
Serious User
T

Joined: Oct 2004
Posts: 1,655
keywords: physics, event, ENABLE_FRICTION, EVENT_FRICTION ?

Manual entry "Gamestudio Physics" might be relevant.

Quoting some version of the manual:
Quote:

As with all collisions, the level must sit in a hollowed sky block for physics collisions to work. Non-physics objects must not collide with physics objects, but physics objects can collide with non-physics objects.


Re: Pointer troubles: Need Help [Re: testDummy] #267689
05/25/09 21:59
05/25/09 21:59
Joined: Feb 2008
Posts: 3,232
Australia
EvilSOB Offline
Expert
EvilSOB  Offline
Expert

Joined: Feb 2008
Posts: 3,232
Australia
Or post the bullets action script and we'll have a look.


"There is no fate but what WE make." - CEO Cyberdyne Systems Corp.
A8.30.5 Commercial
Re: Pointer troubles: Need Help [Re: EvilSOB] #267691
05/25/09 22:16
05/25/09 22:16
Joined: May 2009
Posts: 258
Chicago
J
Jaeger Offline OP
Member
Jaeger  Offline OP
Member
J

Joined: May 2009
Posts: 258
Chicago
Here's the action of the troublesome machine gun bullets... I'll also post the function which creates them, just in case the problem is tied to that...

Code:
........................

// This is from the tank's action, and initiates the function to fire bullets
if(mouse_right){fire_turrmg();}

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

// Function used to fire machine gun (still needs sound bug fixed)
function fire_turrmg()
{
   
   snd_stop(hnd_MGfire);
	hnd_MGfire = ent_playloop(player,snd_792MG,70);
	
	var firing_ang;
	VECTOR mg_barrel;
	vec_for_vertex(mg_barrel,player,28);
	
	 ent_create("MG_bullet.mdl",mg_barrel,mg_action);
  
   wait(-0.04);
   
   if(!mouse_right){snd_stop(hnd_MGfire);}
   
}


.................
// Action to handle machine gun bullets
action mg_action()
{
	
  wait(1);
  
   ang_for_bone(my.pan,player,"turret_bone");
  	ang_rotate(my.tilt,vector(Turr_Ang,0,0));

  c_move(me,vector(15,0,0),NULLVECTOR,IGNORE_YOU);  
  c_setminmax(my);
  
  	phent_settype(me,PH_RIGID,PH_BOX);
	phent_setmass(me,0.012,PH_SPHERE);//45kg
	phent_setfriction(me,100);
	phent_setdamping(me,2,100);

  	phent_addvellocal(my, vector(2000,0,0), nullvector);
wait(1);

  my.emask |= (ENABLE_BLOCK | ENABLE_ENTITY | ENABLE_IMPACT); 
  my.event = impact_mghit;


  set(my,POLYGON);
  set(my,BRIGHT);
  set(my,METAL);
  set(my,INVISIBLE);

var mps;

 while(1)
 {
 	
 	phent_getvelocity(my,mps,NULLVECTOR);

 	wait(1);
   tracerglow.x = - 20; tracerglow.y = 0; tracerglow.z = 0;
	vec_rotate(tracerglow,my.pan);

 	VECTOR tail;
   vec_for_vertex(tail,me,1); 
   
   effect(effect_smktrail, 1, tail,tracerglow);
	
   effect(effect_tracer,1,tail,tracerglow);
   
   vec_rotate(tracerglow,my.pan);
   
   kill_bullet();
   
  wait(1);
 	
 }

wait(1);  
	
}

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

// Oh, and here's the event function

function impact_mghit() 
{
  switch (event_type)
  {
///////////////////////////////////////////////////////////////////////////////////////////////////  	
    case EVENT_IMPACT:
    wait(1);
    
    VECTOR placement;
    placement.x = my.x; placement.y = my.y; placement.z = my.z;
    
    effect(effect_sandhit,5,vector(my.x,my.y,my.z),NULLVECTOR);


    wait(1);
    ent_remove(me);   

///////////////////////////////////////////////////////////////////////////////////////////////////      
    case EVENT_ENTITY:
    wait(1); 

    VECTOR placement;
    placement.x = my.x; placement.y = my.y; placement.z = my.z;
    
    effect(effect_sandhit,5,vector(my.x,my.y,my.z),NULLVECTOR);

    wait(1);
    ent_remove(me);   

///////////////////////////////////////////////////////////////////////////////////////////////////    
    case EVENT_BLOCK: 
    wait(1);

    VECTOR placement;
    placement.x = my.x; placement.y = my.y; placement.z = my.z;
    
    effect(effect_sandhit,5,vector(my.x,my.y,my.z),NULLVECTOR);

    wait(1);
    ent_remove(me);   

    
  }
} 




I think that's all the relevant parts of the code. Funny thing is, the MG bullets are handled almost exactly like the main gun's 75mm bullet (big cannon), but those work perfectly. The MG bullets just act funny sometimes, and won't run their event.

Oh, if you're wondering what the c_move instruction was for, it's to make sure the bullet is carried outside the tank's bounding box before initiating physics and applying velocity. I originally had a problem where firing the gun while the turret faced straight ahead caused rounds to strike the inside of the BB. The c_move instruction fixed that for the main gun's HE rounds. So I used the same thing for the MG rounds.

EDIT: I noticed I've been using some American military jargon, and some of you may not be familiar with it, heheh. So just in case:

MG = machine gun
HE = High Explosive
75mm = The size of the tank's main gun's bullets (in this case)

laugh

Last edited by Jaeger; 05/25/09 22:48.
Re: Pointer troubles: Need Help [Re: Jaeger] #267696
05/25/09 23:04
05/25/09 23:04
Joined: Feb 2008
Posts: 3,232
Australia
EvilSOB Offline
Expert
EvilSOB  Offline
Expert

Joined: Feb 2008
Posts: 3,232
Australia
Try this (untested). Im not good enough with physics to make much use of it,
so Ive by-passed using physics to test for end-of-movement.
Hopefully Ive fixed the event function from failing-to-trigger too.
Click to reveal..
Code:
// Action to handle machine gun bullets
action mg_action()
{
    wait(1);
    ang_for_bone(my.pan,player,"turret_bone");
    ang_rotate(my.tilt,vector(Turr_Ang,0,0));

    c_move(me,vector(15,0,0),NULLVECTOR,IGNORE_YOU);  
    c_setminmax(my);

    phent_settype(me,PH_RIGID,PH_BOX);
    phent_setmass(me,0.012,PH_SPHERE);//45kg
    phent_setfriction(me,100);
    phent_setdamping(me,2,100);

    phent_addvellocal(my, vector(2000,0,0), nullvector);
    wait(1);

    my.emask |= (ENABLE_BLOCK | ENABLE_ENTITY | ENABLE_IMPACT); 
    my.event = impact_mghit;
    set(my,POLYGON|BRIGHT|METAL|INVISIBLE);

    VECTOR tail, lastPos;
    while(1)
    {
        tracerglow.x = - 20; tracerglow.y = 0; tracerglow.z = 0;
        vec_rotate(tracerglow,my.pan);
        vec_for_vertex(tail,me,1); 
        effect(effect_smktrail, 1, tail,tracerglow);
        effect(effect_tracer,1,tail,tracerglow);
        vec_rotate(tracerglow,my.pan);
        //Check if still moving far enough, per frame, to call it "alive".
        vec_set(lastPos, my.x);
        wait(1);
        //this min_distance "10" is just a guess, you'll need to calculate a distance yourself
        if(vec_dist(lastPos, my.x)<10)    break;  
    }
    // kill_bullet();    dunno what "kill_bullet" is for, but I'll assume its the [no-longer-needed] 10 second timer
    phent_settype (me,NULL,NULL);
    ent_remove(me);
}



function impact_mghit()
{
    switch (event_type)
    {
    ///////////////////////////////////////////////////////////////////////////////////////////////////  	
        case EVENT_IMPACT:
            effect(effect_sandhit,5,my.x,nullvector);
            phent_clearvelocity(me);   

    ///////////////////////////////////////////////////////////////////////////////////////////////////      
        case EVENT_ENTITY:
            effect(effect_sandhit,5,my.x,nullvector);
            phent_clearvelocity(me);   

    ///////////////////////////////////////////////////////////////////////////////////////////////////    
        case EVENT_BLOCK: 
            effect(effect_sandhit,5,my.x,nullvector);
            phent_clearvelocity(me);   
    }
}





"There is no fate but what WE make." - CEO Cyberdyne Systems Corp.
A8.30.5 Commercial
Re: Pointer troubles: Need Help [Re: EvilSOB] #267710
05/25/09 23:51
05/25/09 23:51
Joined: May 2009
Posts: 258
Chicago
J
Jaeger Offline OP
Member
Jaeger  Offline OP
Member
J

Joined: May 2009
Posts: 258
Chicago
Thanks again, you EvilSOB! laugh

Well, I won't ever have burning/smoking tracers lying around on the ground anymore, and I can't thank you enough for that. You've shown me twice now that I've been over-complicating my code with unneeded evaluations/instructions/etc.

I don't think this has fixed the event trigger problem though. I've switched it to the one you gave me, which is much shorter and concise. If I can't fix this thing though, that means I'll have "bugged" bullets at some point. I worry that it won't create it's effect, or even worse, won't register hits on an entity and kill/wound them. I'm going to do some more trials and try to see what's going on.

But thanks again! You've helped a lot!

Last edited by Jaeger; 05/25/09 23:51.
Re: Pointer troubles: Need Help [Re: Jaeger] #267712
05/26/09 00:07
05/26/09 00:07
Joined: Feb 2008
Posts: 3,232
Australia
EvilSOB Offline
Expert
EvilSOB  Offline
Expert

Joined: Feb 2008
Posts: 3,232
Australia
Something that may be the cause if your fail-to-hit issues is this I almost remember.

If an entity is both small and fast enough, it can potentially pass its entire mesh/bbox
all the way through the surface of the "hit" models mesh/bbox.
That is, the bullet is now completely "inside" its target, not touching any sides.
If this happens, an event wont be triggered.

I cant remember the fix, but ONE had something to to with a c_trace backwards at
the start of the bullets frame. But Im not sure.

It was discussed at length, with multiple work-arounds suggested, by a few different
threads on this (gamestudio) forum.

I suggest you do a forum search on "bullet" and "too fast"

Best of luck.

PS : Maybe before searching, to test if this IS the problem, try clamping your bullets
slower with phent_setmaxspeed.

PPS : Not sure if its applicable unless the target is a registerd physics object too,
but check the manual for "ph_check_distance". It MAY be of help.


"There is no fate but what WE make." - CEO Cyberdyne Systems Corp.
A8.30.5 Commercial
Re: Pointer troubles: Need Help [Re: EvilSOB] #267714
05/26/09 00:39
05/26/09 00:39
Joined: May 2009
Posts: 258
Chicago
J
Jaeger Offline OP
Member
Jaeger  Offline OP
Member
J

Joined: May 2009
Posts: 258
Chicago
Oh thanks. That could very well be the problem then. These are small bullets, and they're traveling about 3000ft per sec (like real ones). So this is likely the cause. Would making the bullet's physical mesh larger work? Or maybe setting the BB to FAT?

Re: Pointer troubles: Need Help [Re: Jaeger] #267717
05/26/09 01:05
05/26/09 01:05
Joined: Feb 2008
Posts: 3,232
Australia
EvilSOB Offline
Expert
EvilSOB  Offline
Expert

Joined: Feb 2008
Posts: 3,232
Australia
It would "help" your lost bullets issue, but it will remove too much of
the realism in my opinion. Bullets will hit things when they should just graze or miss.

An idea springs to mind. Its not tested but try it.
You can see where it goes cause theres a couple of lines above and below that are unchanged...
Code:
       ///
       //Check if still moving far enough, per frame, to call it "alive".
        vec_set(lastPos, my.x);
        wait(1);
//INSERT START
        if(c_trace(my.x, lastPos, IGNORE_ME))   //if hit something.
        {
           //COMPLETELY THEORETICAL manual event-triggering (never seen or tried before)
           if(you)    event_type = EVENT_ENTITY;    //hit an entity
           else       event_type = EVENT_BLOCK;     //hit terrain/block
           impact_mghit();                          //trigger event manually
           phent_clearvelocity(me);        //stop bullet
           vec_set(lastPos, my.x);         //make it "die" this frame
        }
//INSERT END
        if(vec_dist(lastPos, my.x)<10)    break;  
    }
    ....

NOTE: I havent implemented EVENT_IMPACT because I think the chances of this bullet
being hit by another bullet is small.
So IF you want to keep this chance, let me know and I'll update this snippet.
BUT you will need to apply "push" values to all entities then. (See "push" in manual)


"There is no fate but what WE make." - CEO Cyberdyne Systems Corp.
A8.30.5 Commercial
Page 1 of 5 1 2 3 4 5

Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1