Gamestudio Links
Zorro Links
Newest Posts
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
Change chart colours
by 7th_zorro. 05/11/24 09:25
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
1 registered members (Akow), 1,403 guests, and 9 spiders.
Key: Admin, Global Mod, Mod
Newest Members
AemStones, LucasJoshua, Baklazhan, Hanky27, firatv
19055 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 2 1 2
colliosion detection question, enable_entity #119841
03/27/07 20:06
03/27/07 20:06
Joined: Aug 2005
Posts: 119
Madison, WI
J
JakeL Offline OP
Member
JakeL  Offline OP
Member
J

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 Offline
Expert
Slin  Offline
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
J
JakeL Offline OP
Member
JakeL  Offline OP
Member
J

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: JakeL] #119844
03/27/07 20:50
03/27/07 20:50
Joined: Mar 2006
Posts: 752
Portugal
demiGod Offline
User
demiGod  Offline
User

Joined: Mar 2006
Posts: 752
Portugal
Why are you calling the function remove_projectile(); //remove me once distance is met, if you are using already a trigger event?

And in the event function do you need those waits and sleeps?

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
J
JakeL Offline OP
Member
JakeL  Offline OP
Member
J

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
T
testDummy Offline
Serious User
testDummy  Offline
Serious User
T

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
J
JakeL Offline OP
Member
JakeL  Offline OP
Member
J

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] #119848
03/28/07 22:24
03/28/07 22:24
Joined: Aug 2005
Posts: 119
Madison, WI
J
JakeL Offline OP
Member
JakeL  Offline OP
Member
J

Joined: Aug 2005
Posts: 119
Madison, WI
Well thanks to testDummy, it works how I would like. The key was moving the ent_remove(me) to the move_projectile() function and breaking out of the while loop by setting a flag to on in the trigger event.

Now, I know its fixed, but can anyone tell me why my original code didn't work. I have used ent_remove() inside trigger events before and never had a problem. This is used in AUM all the time. Infact, the asteroids which I shoot in the game do this now and work perfectly. Are there special cases for trigger events? Does the while loop inside the function which calls the event interfere with the trigger event?

Just a quick note: I'm pretty sure while(me) or while(my) is the same as while (me != null).

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 Offline
Expert
xXxGuitar511  Offline
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
Re: colliosion detection question, enable_entity [Re: xXxGuitar511] #119850
03/28/07 23:13
03/28/07 23:13
Joined: Aug 2005
Posts: 119
Madison, WI
J
JakeL Offline OP
Member
JakeL  Offline OP
Member
J

Joined: Aug 2005
Posts: 119
Madison, WI
Then, why dosen't my original code work?

Page 1 of 2 1 2

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