|
movement making collisions crash
#437943
03/01/14 23:22
03/01/14 23:22
|
Joined: Dec 2009
Posts: 361
rtsgamer706
OP
Senior Member
|
OP
Senior Member
Joined: Dec 2009
Posts: 361
|
Hi, I started programming an enemy into my game. I got it to die when it collides with a laser without any problems. Oddly, once I told the enemy to start moving forwards the game would crash whenever it collided with a laser. No error message or anything, the game just closes. Here are the actions for the laser and the enemy:
function delete_anim()
{
var destroy_percent = 0;
while (my)
{
destroy_percent += 6;
ent_animate(my,"deleting", destroy_percent, 0);
if (destroy_percent >= 100)
ent_remove(me);
wait(1);
}
}
function delete()
{
if (event_type == EVENT_IMPACT || event_type == EVENT_ENTITY)
{
wait(1);
ent_remove(you);
ent_morph(me, "goomba_death.mdl");
delete_anim();
}
}
action enemy()
{
c_setminmax(me);
my.emask |= (ENABLE_IMPACT | ENABLE_ENTITY);
my.event = delete;
var temp;
var walk_percent;
while (my)
{
vec_set (temp, ship.x);
vec_sub (temp, my.x);
vec_to_angle(my.pan, temp);
my.tilt = 0;
walk_percent += 2;
ent_animate(my,"step", walk_percent, ANM_CYCLE);
c_move (me, vector(15*time_step, 0, 0), nullvector, GLIDE | IGNORE_PASSABLE);
wait(1);
}
}
action beam()
{
c_setminmax(me);
vec_for_vertex(my.x, ship, 3);
my.pan = delete_ship.pan;
var laser_lifetime = 200;
while (my)
{
c_move (me, vector(45*time_step, 0, 0), nullvector, GLIDE | IGNORE_PASSABLE);
laser_lifetime--;
if (laser_lifetime <= 0)
ent_remove(me);
wait(1);
}
}
If I remove the movement command in the enemy it dies fine again. I'm really lost as to why this is thanks for the help
|
|
|
Re: movement making collisions crash
[Re: rtsgamer706]
#437945
03/01/14 23:44
03/01/14 23:44
|
Joined: Jan 2002
Posts: 4,225 Germany / Essen
Uhrwerk
Expert
|
Expert
Joined: Jan 2002
Posts: 4,225
Germany / Essen
|
The event function itself should be simple. It normally should only transfer information to the entities' main function - it shouldn't perform instructions that can trigger events itself, displace entities, or change anything else in the level. Thus instructions like c_move, ent_create, ent_remove, c_trace etc. must not be performed http://www.conitec.net/beta/aentity-event.htm
Always learn from history, to be sure you make the same mistakes again...
|
|
|
Re: movement making collisions crash
[Re: Uhrwerk]
#437946
03/02/14 00:08
03/02/14 00:08
|
Joined: Dec 2009
Posts: 361
rtsgamer706
OP
Senior Member
|
OP
Senior Member
Joined: Dec 2009
Posts: 361
|
So I changed the event so now it's just (health being a skill I define at the top):
function delete()
{
if (event_type == EVENT_IMPACT || event_type == EVENT_ENTITY)
{
wait(1);
my.health -= 1;
}
}
and put the rest of the stuff into the action of the entity, so in the loop I have:
if (my.health <= 0)
{
if (you)
ent_remove(you);
ent_morph(me, "death_model.mdl");
destroy_percent += 10;
ent_animate(my,"deleting", destroy_percent, 0);
if (destroy_percent >= 100)
{
wait(1);
if (me)
ent_remove(me);
}
wait(1);
}
now it finishes the death animation and then exists the game. Putting the remove(you) command into the event doesn't seem to change anything
|
|
|
Moderated by mk_1, Perro, rayp, Realspawn, Rei_Ayanami, rvL_eXile, Spirit, Superku, Tobias, TSG_Torsten, VeT
|