Killing all Clones

Non-platform specific questions.

Killing all Clones

Postby 666applestore » Thu May 24, 2012 5:52 pm

Hi,

Pretty simple question here, and am having trouble finding it on forum. I'm cloning a common enemy in a sidescrolling platform game. I'm using a Collision and DestroyActor on the enemy when he is hit with a bullet. However, this obviously ends up destroying all of the clones, when I just want the bullet to kill that specific clone. Is there a code I can add to the DestroyActor or Collision that can do this? Some kind of "untether from other clones" button or script? Otherwise I would have to add a new Actor, import graphics and scripts over and over again for each of this type of enemy (which is tedious).

Thanks!
666AppleStore
User avatar
666applestore
 
Posts: 3
Joined: Wed May 23, 2012 1:14 am
Score: 0 Give a positive score

Re: Killing all Clones

Postby phyzix5761 » Thu May 24, 2012 6:06 pm

Hi there. First create an actor variable named killme. In the collision event of the clone add

Code: Select all
killme=1;


in the draw event of the clone add

Code: Select all
if(killme==1)
{
   //blah blah blah
   DestroyActor("Event Actor");

}


that should only destroy the clone that collided.
phyzix5761
 
Posts: 261
Joined: Sun Feb 27, 2011 4:28 am
Score: 18 Give a positive score

Re: Killing all Clones

Postby 666applestore » Thu May 24, 2012 7:03 pm

Hey, thanks for the help, I'm getting closer, but i havent really worked w variables before (and im not that great w code). I'm doing this with two clones for now (enemy.0, enemy.1) It now is killing the clone specified (enemy.0), even if I shoot the other clone. When I look in the code I can see that whatever I change in the DrawActor is changed in both clones so I must not be doing something right with the variable.

Here's what I did following your directions

1. I went to Global Code, clicked Variables, clicked Add Variable, named it killme, it's an Integer, Actor Variable, Array:No, Size: nothing, Save Group: nothing. Clicked OK.

2. Removed DestroyActor in Collision with Bullet

3. Added new Collision Event on Any Side Of Bullet: killme=1;

4.Added to DrawActor > Script Editor >
Code: Select all
if(killme==1)
{
     
     DestroyActor("enemy.0");

}


Thanks again!
User avatar
666applestore
 
Posts: 3
Joined: Wed May 23, 2012 1:14 am
Score: 0 Give a positive score

Re: Killing all Clones

Postby 666applestore » Thu May 24, 2012 7:06 pm

ok I needed to just put "Event Actor" and not specify the enemy still. It seems to be working now, great thanks!
User avatar
666applestore
 
Posts: 3
Joined: Wed May 23, 2012 1:14 am
Score: 0 Give a positive score

Re: Killing all Clones

Postby skydereign » Thu May 24, 2012 8:29 pm

In a collision event you can specify the event actor and the colliding actor (the other actor).
bullet -> Collision with enemy -> Script Editor
Code: Select all
DestroyActor("Collide Actor");
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score


Return to General

Who is online

Users browsing this forum: No registered users and 1 guest

cron