Spawn different animation/direction clones from single Actor

You must understand the Game Editor concepts, before post here.

Spawn different animation/direction clones from single Actor

Postby Zivouhr » Tue Nov 03, 2015 4:48 am

Spawn different animation/direction clones from single Actor:

Goal: Rather than create and reprogram a new enemy actor for each new monster's appearance, to have the spawn point randomly generate different monsters and have the direction they're facing animate per monster, but using a single actor for the spawned enemy within the enemy spawner actor. So two actors created total: A spawn point, and the monster actor being spawned, which will have different animations for each new monster within the animation index.

The enemy will be able to follow the player with a moveTo event and will face left or right, depending on which side of the player the enemy clone is on.

I'm testing out variables, but they're not working as intended. Closest I get is two different monsters, but then the spawn point only produces the second monster over and over, and its animation flickers instead of going through the animation smoothly.

Here's what I tried:

"enemy" Actor/draw actor/script:
Code: Select all
if (za==1) //variable for zombie A
{
if(x>player.x) // if enemy is to the right of player facing left towards player
{
ChangeAnimation ("Event Actor" , ZombieaL00001", NO_CHANGE);
//I tried animindex=0; here, but then that didn't animate correctly, and twitches.
}

if(x<player.x) // if enemy is to the LEFT of player facing Right towards player
{
ChangeAnimation ("Event Actor" , ZombieaR00001", NO_CHANGE);
//I tried animindex=1; here, but then that didn't animate correctly, and twitches.
}}

if (zb==1) //variable for zombie B (also animations within the same actor)
{
if(x>player.x) // if enemy is to the right of player facing left towards player
{
ChangeAnimation ("Event Actor" , ZombiebL00001", NO_CHANGE);
//I tried animindex=2; here, but then that didn't animate correctly, and twitches.
}

if(x<player.x) // if enemy is to the LEFT of player facing Right towards player
{
ChangeAnimation ("Event Actor" , ZombiebR00001", NO_CHANGE);
//I tried animindex=3; here, but then that didn't animate correctly, and twitches.
}}



//////
Spawn Point/timer/script editor: //this is after creating the timer 3 second loop.
Code: Select all
type=rand(2);

switch(type)
{
case 0;
CreateActor ("enemy", "ZombieaR00001", "(none)", "(none)", 0, 0, false);
za=1;  //zombie reference variable A
break;

case 1;
CreateActor ("enemy", "ZombiebR00001", "(none)", "(none)", 0, 0, false);
zb=1;  //zombie variable B
break;
}


Variables declared under script editor/variables:
za is a integer global.
zb is an integer global too. I tried making them real actors, but that didn't work for some reason.

Just wonder what I might be missing to get the single enemy actor to display different animations and get the animations to play without twitching and not going through the animations.

I was going to put something in create actor, but that didn't work. Any help would be appreciated, thank you. I did a search but couldn't find this topic answered yet.

8)

I'm wondering if maybe the spawn point actor's case 0 and case 1 are creating the actor and that actor's start animation are somehow interfering? I really wish we could createActor for clones. That would've saved a ton of time and challenging coding. So we'd be able to create "enemy.2", "enemy.4", whenever we wanted, but have each enemy clone have a different animation set.
City of Rott Game created on Game Editor http://cityofrott.wordpress.com/
User avatar
Zivouhr
 
Posts: 549
Joined: Sat May 17, 2014 2:12 pm
Score: 59 Give a positive score

Re: Spawn different animation/direction clones from single A

Postby Hares » Wed Nov 04, 2015 9:53 pm

Animindex is read only.

You are checking the animation constantly in the draw actor script.
Try putting an extra if statement to check if the desired animation is not already playing.

Code: Select all
if (za==1) //variable for zombie A
{
    if(x>player.x) // if enemy is to the right of player facing left towards player
    {
        if(animindex!=0)
       {
           ChangeAnimation ("Event Actor" , ZombieaL00001", NO_CHANGE);
       }
    }
}

User avatar
Hares
 
Posts: 105
Joined: Fri Dec 20, 2013 8:39 pm
Location: Belgium
Score: 14 Give a positive score

Re: Spawn different animation/direction clones from single A

Postby Zivouhr » Thu Nov 05, 2015 2:11 am

Hares wrote:Animindex is read only.

You are checking the animation constantly in the draw actor script.
Try putting an extra if statement to check if the desired animation is not already playing.

Code: Select all
if (za==1) //variable for zombie A
{
    if(x>player.x) // if enemy is to the right of player facing left towards player
    {
        if(animindex!=0)
       {
           ChangeAnimation ("Event Actor" , ZombieaL00001", NO_CHANGE);
       }
    }
}



Thank you Hares! I'll give that a try and good tip about Draw Actor running on every frame to explain the twitching animation. 8)
City of Rott Game created on Game Editor http://cityofrott.wordpress.com/
User avatar
Zivouhr
 
Posts: 549
Joined: Sat May 17, 2014 2:12 pm
Score: 59 Give a positive score

Re: Spawn different animation/direction clones from single A

Postby Zivouhr » Fri Nov 06, 2015 12:34 am

UPDATE:

Finally figured out how to make a single actor create multiple enemies from a spawn point that can animate facing left or right depending on the enemy and placement of the player.

So now zombie za, who is walking left or right with his hands extended out, walks left or right properly from being spawned.
Zombie zb, who is walking left or right with his hands clenched, walks left or right properly from being spawned.
Zombie zc, who is walking left or right while slumping over, walks left or right properly from being spawned.

etc.

The real advantage to all of this? I don't have to recreate an entirely new actor and duplicate ALL of the extensive actor events for collisions, draw, create, out of vision, etc, since this single actor can now handle it through subtle variable changes and including all of the different zombies and their left, right animations in this single zombie actor, who is brought to life by the zombie spawn point, from which the zombies will originate into the game's world.

It could use refinement, or a more compact way to express this code, but the key was to indicate which clone would represent which zombie variable.

For the Variables, such as za, zb, zc, etc, I made them each a Real, Actor variable in the script window, not Global, Integer.

enemy/create actor/script:
Code: Select all
if(cloneindex==0) za=1;
if(cloneindex==1) zb=1;
if(cloneindex==2) zc=1;

if(cloneindex==3) za=1;
if(cloneindex==4) zb=1;
if(cloneindex==5) zc=1;

if(cloneindex==6) za=1;
if(cloneindex==7) zb=1;
if(cloneindex==8) zc=1;

//etc... I'm thinking there has to be an array or loop that will allow this to repeat without creating 1000 if statements. Just //not sure so I'll search the forum.

That was the key though, as before, the zombie spawner wasn't creating anything but what was already in the createActor statement. So if it was zombieaR00001 facing right, that's what it would create. Only when I added the clone index reference did it acknowledge the za=1, zb=1 variables associated with it in the timer event of the zombie spawner code in the first post I made.

I did discover the animations also worked properly even in the draw actor event without adding the animindex!=1, etc, coding, but thanks for the tip!


So the only challenge left is when it gets to the end of the listed clones, it starts spawning motionless zombies. At that point, I'll have to destroy the spawner and figure something else out to keep the enemies spawning and varied.

EDIT:
After some research, I'll try getClone functions instead of if statements, based on LCL's suggestion in an old post.

Code: Select all
getclone("enemy.0")->za=1;
getclone("enemy.1")->zb=1;
getclone("enemy.3")->zc=1;

getclone("enemy.4")->za=1;
getclone("enemy.5")->zb=1;
//
getclone("enemy.1001")->zc=1;


I'll test if it works. Okay, it works. Thanks Lcl. 8)
City of Rott Game created on Game Editor http://cityofrott.wordpress.com/
User avatar
Zivouhr
 
Posts: 549
Joined: Sat May 17, 2014 2:12 pm
Score: 59 Give a positive score

Re: Spawn different animation/direction clones from single A

Postby digiot » Fri Nov 06, 2015 11:14 pm

So you have found the solution on your own.
I wanted to help you, but I couldn't figure out, how the scripts were intended to work.
The global vars were just mysterious for me.
Now you are on the right way, getclone is your friend !

Cheers !
User avatar
digiot
 
Posts: 211
Joined: Sat Mar 17, 2012 2:29 pm
Score: 7 Give a positive score

Re: Spawn different animation/direction clones from single A

Postby Zivouhr » Sat Nov 07, 2015 3:21 pm

digiot wrote:So you have found the solution on your own.
I wanted to help you, but I couldn't figure out, how the scripts were intended to work.
The global vars were just mysterious for me.
Now you are on the right way, getclone is your friend !

Cheers !


Thanks Digiot! Yes, I got it working well now, and can have 10+ unique and different zombies/monsters now without having to program a huge list of options for each unique zombie, which is a huge relief. :D

To stop the spawn points from creating more zombies, within the create actor of the enemy, just add an eventDisable for the spawner at the 1001th clone, instead of referencing it to a zombie variable like za, zb, zc, zd, etc.
City of Rott Game created on Game Editor http://cityofrott.wordpress.com/
User avatar
Zivouhr
 
Posts: 549
Joined: Sat May 17, 2014 2:12 pm
Score: 59 Give a positive score


Return to Advanced Topics

Who is online

Users browsing this forum: No registered users and 1 guest

cron