Page 1 of 1

Actor Wanting to Choose Random Path

PostPosted: Sat Dec 03, 2005 11:18 pm
by GregSmith
If an actor is already moving along a predefined path, with animation, and he comes to a region where he could progress by switching to any one of a number of predefined paths that appear to merge at that juncture, what would be the simplest, non-coding solution to cause that actor, with his animation, to continue moving along any of those other paths, in a random order?

To clarify the problem:

Imagine a psuedo-3D scene where the actor is moving "away" from the camera into the distance, getting smaller, to simulate perspective. He then comes to a rock formation and could move on a predefined path to the left, the right, "around" the rock formation, or back toward the camera. Depending on which path was taken, his animation would change to reflect which direction he was traveling toward.

So, two things would happen at the same moment: the actor would randomly switch paths, and, depending on which path was selected, would also change his animation to correspond with that path direction.

Thanks,

Greg Smith

PostPosted: Sun Dec 04, 2005 10:18 am
by Novice
You can do it this way:
on path finish --> change path (random)
but then you will have the problem you will have to have only 4 paths because if you have more they will all be included in the random path chnage.

The better way to do it includes little coding so bear with me.
Here we are assuming that your animation and path names are 1,2,3,4.
path finish(1)--> script editor
Code: Select all
int animation=rand(2);

if (animation==0)
{
    ChangePath("Event Actor", "2", BOTH_AXIS);
    ChangeAnimation("Event Actor", "2", FORWARD);
}
else if (animation==1)
{
    ChangePath("Event Actor", "3", BOTH_AXIS);
    ChangeAnimation("Event Actor", "3", FORWARD);
}
else if (animation==2)
{
    ChangePath("Event Actor", "4", BOTH_AXIS);
    ChangeAnimation("Event Actor", "4", FORWARD);
}


Just paste this in to script editor i checked it and it works.
Hope it helps.

PostPosted: Mon Dec 05, 2005 5:08 pm
by GregSmith
Novice:

Thanks for the advise. I would prefer to refrain from coding whenever possible, so the 4 path limitation might be o.k. Can a path be constrained to rotate and advance along another path? That would allow for some very "random-like" behavior, especially if the sprite were animated independtly of its path movements.

Greg Smith

PostPosted: Mon Dec 05, 2005 5:18 pm
by makslane
You can use parented actors to make composite paths.

For example:

- Put the path1 in the actor1
- Put the path2 in the actor2

Now, make the actor1 parent of actor2

The actor1 will move along the path1, and the actor2 will move along the path2, but the final movement for the actor2 will be the composition from path2 with path1.