Random Movement

Cyanocobalamin

  • Posts: 27
Hello, I'm not the best coder (even worse with this API and Flash.)
But, I know there is a few things in the StencylForge for 4 way random direction.
What I'm looking for is 8 way random direction movement. I've spent a while trying to think/get something to work by looking at the various 8 way player movements, but I am at a loss.
:c

EDIT:
I actually got an 8 way random direction to work for NPC's. It acts a little weird because of randoms, and if anyone is interested I'll post it.
I derived it from an 8 way movement script, and a 4 way random NPC direction script, so thanks to them. :)

« Last Edit: November 28, 2011, 07:35:16 pm by Cyanocobalamin »

Ceric

  • *
  • Posts: 610
Cool. I made a four-way random movement behavior a while ago. I think people would be interested in this if it's clear how to set it up.

Cyanocobalamin

  • Posts: 27
It "works" and is indeed 8 ways, however it's not perfect.

I think it's just something that works for no real reason...
What I need a little help with though is, when the monsters or whatever bump into a wall, it says turn around and go the other way.
I think it's going to be complicated because of the randomness, any ideas?

Ceric

  • *
  • Posts: 610
What problem are you running into, exactly?

I have mine set up so it only sends a "RandomMovement" message every couple of seconds. That basically means when an actor using this hits something and goes the opposite way, it will do that for a while until it either runs into something else, or the behavior sends the "RandomMovement" message again, causing the actor to change directions.

Do you need helping setting up the reverse direction part of the behavior?

Cyanocobalamin

  • Posts: 27
Hi, I think the script it's self is awful, but I would like to implement almost exactly what you said you created.
I currently have it set up so it picks a random time and then changes to a random direction. sometimes they just hit a wall and sit there for a long time.  Thanks a lot for the assistance.

Ceric

  • *
  • Posts: 610
The code I have here took a few iterations to get right. The first part is what controls how often the random direction change happens. The part in the second pic shows how I handle the collisions.

The rest of the behavior (not shown) just determines which animation to show, and which direction to move (and at what speed), for the four different directions (1, 2, 3, and 4). You would want to set that up for 8 directions rather than 4. The same goes for the different collision options. It seems complicated but it would mostly be tedious to set up. You would just want to make sure that you covered all of the collision options. Just use the "and" blocks between the different collision checks ("hit from the right side AND hit from the top," "hit from the left side AND hit from the bottom," etc.).

« Last Edit: November 28, 2011, 11:06:52 pm by Ceric »

Cyanocobalamin

  • Posts: 27
Hi, you've helped me a lot and now I've determined what I want to happen, but I'm having issues trying to implement it.
As of now when the monster spawns it move in a random direction and stops.
What I want is it to (for example) get hit on the left side, then pick one of 3 directions to move to on the right side away from the wall.
It sounds confusing, but it doesn't work. If needed I can attach what I have thus far.

Ceric

  • *
  • Posts: 610
You'll have to play around with this a bit, but the attached pic shows the basic structure for the "collision" part of the behavior and the movement part that would go in the "always" block.

If you want to have 8 separate directions, you would just need to make the random number between 1 and 7 and then have the RandomDirection attribute be set to all 7 directions save for the one that is the current direction the actor is traveling in.

This is mostly tedious to set up, more than anything else.

Note that the RandomDirection attribute is a number-type attribute, and the "Speed" attribute is a number-type attribute, too. The Direction attribute is a text-type attribute.

Cyanocobalamin

  • Posts: 27
I managed to get exactly what I was looking for, you've helped a lot thanks a million. I'll show you the confusing mess I have. I'm sure everything could be improved on it, but take a look.

Any input you have would be appreciated very much.

My idea is very simple, I don't need speed, animation changes or anything.

Ceric

  • *
  • Posts: 610
No problem, happy to help out. Looks cool. The only suggestion I would make would be if you had a situation in your game where the randomly moving actor might move along a while without running into anything.

If that could be the case, you might want to add a "do after" or "do every" block and change the random number for the direction after a set amount of time.

If your actor is basically going to start moving and pretty much immediately start bouncing off of things, then what you have should be fine.

So are you getting a better idea of how to use StencylWorks' Design Mode after all of this? What do you think of the toolset so far?

Cyanocobalamin

  • Posts: 27
Yes that's exactly what I needed so I'm rather happy with it.

And thus far Stencyl seems to great, I'm liking it very much and I can see myself using it for a long time to come.

I keep running into (what I'm sure is) problems that everyone has the first time. I'll work them out eventually, thanks again for all of the help, I feel bothersome.

Ceric

  • *
  • Posts: 610
No worries. The forums are here to help users out.

utakia

  • Posts: 1
EDIT:
I actually got an 8 way random direction to work for NPC's. It acts a little weird because of randoms, and if anyone is interested I'll post it.
I derived it from an 8 way movement script, and a 4 way random NPC direction script, so thanks to them. :)

I'm interested in this 8 way random direction movement thing for NPC's.