1 registered members (Akow),
1,403
guests, and 9
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
colliosion detection question, enable_entity
#119841
03/27/07 20:06
03/27/07 20:06
|
Joined: Aug 2005
Posts: 119 Madison, WI
JakeL
OP
Member
|
OP
Member
Joined: Aug 2005
Posts: 119
Madison, WI
|
I am making a space shooter game and am having problems with collision detection. The ship "shoots" out a simple model (using c_move) which has my.enable_entity = on assigned to it and an action to remove it if it comes in contact with an other model, but the action seems to never be triggered. The projectile destroys its target but countinues to fly away, never getting removed itself until it has reached a maximum distance. I want it removed right after it hits any model Here is the code. This should be simple. Any help here would be awesome. Code:
function move_projectile() { var maximum_distance = 15; var projectile_speed = 50; var effect_speed = 0; wait(1); c_setminmax(me); my.invisible = on; my.enable_entity = on; my.pan = player.pan; my.tilt = player.tilt; my.event = remove_projectile; while (maximum_distance > 0) && (my) { maximum_distance -= 1 * time; c_move (me, projectile_speed, nullvector, ignore_passable); vec_set (temp.x, my.x); effect (photon_effect, 1, temp, effect_speed); wait (1); } remove_projectile(); //remove me once distance is met }
function remove_projectile() { wait(1); //wait one frame my.event = null; my.passable = on; my.invisible = on; sleep (2); ent_remove(me); }
If you need graphic resources, or just want to see some of my work, check out our site AdenFall Software.
|
|
|
Re: colliosion detection question, enable_entity
[Re: JakeL]
#119842
03/27/07 20:33
03/27/07 20:33
|
Joined: May 2005
Posts: 2,713 Lübeck
Slin
Expert
|
Expert
Joined: May 2005
Posts: 2,713
Lübeck
|
I can´t really find any mistakes, except of the order. Try defining the event function before the function triggering the event, or place a function prototype over the move_projectile() function:
function remove_projectile();
function move_projectile() { var maximum_distance = 15; var projectile_speed = 50; var effect_speed = 0; wait(1); c_setminmax(me); my.invisible = on; my.enable_entity = on; my.pan = player.pan; my.tilt = player.tilt; my.event = remove_projectile; while (maximum_distance > 0) && (my) { maximum_distance -= 1 * time; c_move (me, projectile_speed, nullvector, ignore_passable); vec_set (temp.x, my.x); effect (photon_effect, 1, temp, effect_speed); wait (1); } remove_projectile(); //remove me once distance is met }
function remove_projectile() { wait(1); //wait one frame my.event = null; my.passable = on; my.invisible = on; sleep (2); ent_remove(me); }
I´m not sure but at least, this could be the problem.
Slin
|
|
|
Re: colliosion detection question, enable_entity
[Re: Slin]
#119843
03/27/07 20:45
03/27/07 20:45
|
Joined: Aug 2005
Posts: 119 Madison, WI
JakeL
OP
Member
|
OP
Member
Joined: Aug 2005
Posts: 119
Madison, WI
|
Thank Slin for the idea, but I have already defined the function prototype at the beginning of my script. I also tried switching the order, but I am still having the problem.
If you need graphic resources, or just want to see some of my work, check out our site AdenFall Software.
|
|
|
Re: colliosion detection question, enable_entity
[Re: demiGod]
#119845
03/27/07 20:54
03/27/07 20:54
|
Joined: Aug 2005
Posts: 119 Madison, WI
JakeL
OP
Member
|
OP
Member
Joined: Aug 2005
Posts: 119
Madison, WI
|
demiGod - I am also destroying the projectile when it reaches a certain distance. This way the projectile won't move forever or destroy something incredibly far away. This would be seperate from the trigger event.
The wait might not be needed, but it makes no difference if its in there or not. The sleep is needed, because I plan on playing a sound and explosion before the projectile is removed.
Last edited by JakeL; 03/27/07 20:56.
If you need graphic resources, or just want to see some of my work, check out our site AdenFall Software.
|
|
|
Re: colliosion detection question, enable_entity
[Re: JakeL]
#119846
03/28/07 05:53
03/28/07 05:53
|
Joined: Oct 2004
Posts: 1,655
testDummy
Serious User
|
Serious User
Joined: Oct 2004
Posts: 1,655
|
Code:
// example define _distMoved, skill22; define _hit, flag7;
function projectileEvent() { if (event_type == event_entity || event_type == event_impact || event_type == event_push) { my._hit = ON; my.event = NULL; if (you != NULL) { //shouldn't be //you._hit = ON; //you._hullIntegrity = max(you._hullIntegrity - my._hitPower, 0); } } } function move_projectile() { var maximum_distance = 1000; var projectile_speed = 50; var effect_speed = 0; wait(1); c_setminmax(me); my.invisible = on; //enable events my.enable_entity = on; my.enable_impact = on; my.enable_push = on; if (player != NULL) { my.pan = player.pan; my.tilt = player.tilt; } my.event = projectileEvent; while (me != NULL) { if (my._distMoved > maximum_distance || my._hit == ON) { break; } my._distMoved += c_move (me, vector(projectile_speed, 0, 0), nullvector, ignore_passable); vec_set (temp.x, my.x); effect (photon_effect, 1, temp, effect_speed); wait (1); } //removal of entity if (me != NULL) { if (my._hit == ON) { //create hit flash //play sound using hit flash } else { if (my._distMoved >= maximum_distance) { //fade out? } } ent_remove(me); } }
|
|
|
Re: colliosion detection question, enable_entity
[Re: testDummy]
#119847
03/28/07 21:41
03/28/07 21:41
|
Joined: Aug 2005
Posts: 119 Madison, WI
JakeL
OP
Member
|
OP
Member
Joined: Aug 2005
Posts: 119
Madison, WI
|
Thanks testDummy. I'll take a look at this and see if it fixes my problems.
If you need graphic resources, or just want to see some of my work, check out our site AdenFall Software.
|
|
|
Re: colliosion detection question, enable_entity
[Re: JakeL]
#119849
03/28/07 22:43
03/28/07 22:43
|
Joined: Mar 2006
Posts: 2,503 SC, United States
xXxGuitar511
Expert
|
Expert
Joined: Mar 2006
Posts: 2,503
SC, United States
|
while(my): yes, this is the same...
*You can use ent_remove inside events, but if you do so, you MUST use a wait(1); before calling ent_remove()...
xXxGuitar511 - Programmer
|
|
|
|