SOLVED: walkable areas problem

Started by stepsoversnails, Tue 22/03/2011 06:55:53

Previous topic - Next topic

stepsoversnails

I'm making a game that has two separate characters you can control but one of the characters can go places the other one can't.
I wanted to know a script that would allow one character to enter these areas but not the other.
i assume walkable areas would have a lot to do with this but i'm not sure.
I know there is disable walkable area and restore walkable area but the problem with that is that one character can shout to the other one and they will walk over to them.
so how can i disable the walkable area only for that one character to stop him from walking on it and if he tries to id like him to play a custom animation and to stop trying to walk on it.
also, i have no idea where i would put this script.
maybe the room load, i'm really not sure.
thank you!

barefoot

Hi

it depends a lot on the whole picture... is one char following another or are they completely independent?

What are the areas one char can't go? is it another room? an area of a room?

If you want an action to happen as soon as the room loads you should put script in after room fades in rather than when room loads.

I'm sure others here will be able to give you more/better pointers.....

barefoot



I May Not Be Perfect but I Have A Big Heart ..

Khris

In general, what you do is turn off the areas only accessible by one character whenever the player is controlling the other one. In other words, the button used to switch characters also has to turn walkable areas on/off.

You have to use some kind of convention, e.g. walkable areas with odd numbers are accessible by both, those with even numbers only by the face. You can switch walkable areas that aren't actually drawn, so that part is relatively easy to implement.

To find out whether a character hit the edge of a walkable area, you basically have to track their movement and compare it to the target destinations.

I'm not going to go into much detail here; it's certainly ambitious for a first project and while it's an ingenious idea, coding it is going to get complex fast, I fear.

stepsoversnails

your idea about disabling walkable areas of certain numbers has worked really well.
thank you for that suggestion.
The only thing i'm left with now is making sure the other character can't walk onto it.
I've set the all restricted walkable areas to walkable area 2
the character calls to the other character by using the talk icon on him

Code: ags
function cEgo_Talk()
{
Display("C'mere!");
cEgo.Walk(cChar1.x + 30, cChar1.y - 0, eBlock);
}


i figure this is the best place to stop the character from walking onto walkable area 2, right?
i just don't know how to code it.

TomatoesInTheHead

Maybe not the best way, but you could just check if the destination is on a non-restricted walkable area. Something like this:

Code: ags
function cEgo_Talk()
{
cChar1.Say("C'mere!");
int destination = GetWalkableAreaAt(cChar1.x-GetViewportX() + 30, cChar1.y-GetViewportY());
if (destination != 2 && destination != 0)
  cEgo.Walk(cChar1.x + 30, cChar1.y, eBlock);
else
  cChar1.Say("Oh I forgot, he can't walk here.");
}


So, instead of getting as close as he can, which would be preferable, cEgo wouldn't walk at all. But this should solve the problem.

Khris

It's a blocking walk, so why not just do:

Code: ags
function cEgo_Talk() {
  Display("C'mere!");
  RemoveWalkableArea(2);
  cEgo.Walk(cChar1.x + 30, cChar1.y - 0, eBlock);
  RestoreWalkableArea(2);
}

stepsoversnails

both of these solutions worked perfectly.
I'm not sure which one i will be using though.
I'll have to test them both out in different areas and different rooms of the game.
thank you so much!

SMF spam blocked by CleanTalk