movement making collisions crash

Posted By: rtsgamer706

movement making collisions crash - 03/01/14 23:22

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:
Code:
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
Posted By: Uhrwerk

Re: movement making collisions crash - 03/01/14 23:44

Originally Posted By: The mighty manual
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
Posted By: rtsgamer706

Re: movement making collisions crash - 03/02/14 00:08

So I changed the event so now it's just (health being a skill I define at the top):
Code:
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:
Code:
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
© 2024 lite-C Forums