Pretty much anything random is done with the rand function. If you want to spawn things on the x axis, with random distances between them then you can do so by looping CreateActor with the same y, and a random x. For instance, you can do something like this.
- Code: Select all
int i;
for(i=0;i<20;i++)
{
CreateActor("actor", "anim", "(none)", "(none)", i*100+rand(50), height/2, false);
}
They'll be created at relatively uniform intervals, but have a random aspect. But, if you want truly random instead of progressively created, you can just use rand instead of the for loop.
actor.0 (000-050, 240)
actor.1 (100-150, 240)
actor.2 (200-250, 240)
actor.3 (300-350, 240)
and so on...
To have them have random animations you can add this event. All you'd need to change is num_of_animations to the actual number of animations the actor has.
actor -> Create Actor -> Script Editor
- Code: Select all
ChangeAnimation("Event Actor", getAnimName(rand(num_of_animations)), FORWARD);
Now, the if statement worked because when yvelocity is greater than whatever you set it to, that means the actor is falling. Because of the actor's gravity in its draw script, it will constantly be falling even while it is on the tiles, but it is also constantly colliding with the ground, and therefore reseting its yvelocity. If the actor was able to fall for 2-3 frames, then yvelocity would be greater than three, and therefore you would want a landing animation to activate. If the actor hadn't been falling for more than two frames, that means they have been running on tiles and you don't want to trigger the animation change.