Automatically Walking off a Region (Solved)

Started by Goldenrod111, Sat 22/03/2008 20:30:19

Previous topic - Next topic

Goldenrod111

I want to have a region where, if the player is any character except character 2, he stops and moves back off of the region. I found a similar topic here, but my usage is somewhat different. It sounds like their region is rectangular but mine isn't (see below). Also, from looking at the code, it looks like they have their character walking to a certain spot. I want my character to walk off the region, but not go to the same spot every time or walk a long distance. Can someone help me with this? I am using v3.0.

Code: ags
function region1_WalksOnto()
{
  if (player.ID == 2){
  }
  else{
    Display("Since the ground doesn't look very sturdy, you deside not to walk there.");
  }
}


Rui 'Trovatore' Pires

Well, it may not be a very efficient solution, but here's what I'd try to do and hope it worked -

Surround the region in question with another region, outlining it. Dunno whether you should keep it adjacent to region1 or whether you should leave some *small* blank area, but that's just experimentation. And make it so that when the player leaves that region his coordinates are stored. Then read them back when he actually steps onto region one, have him move to those stored coordinates.
Reach for the moon. Even if you miss, you'll land among the stars.

Kneel. Now.

Never throw chicken at a Leprechaun.

lemmy101

#2
That would be ideal, if you want them to walk to the specific place they entered the region on. Alternatively if you want to move them to the closest place outside the region they are stood on, not the previous place, you could do this:

and I'm only supposing this out of the help file, it's got a couple of assumptions and I've not tried it, but in theory it should work:

My solution would be to create a dummy character (cInvis) who wasn't collidable, and had an invisible sprite, to help determine where the closest point outside the region to where your character is currently stood is. Then walk to where your dummy character gets moved to by "PlaceOnWalkableArea".

Next, make two walkable areas. One covering the "region" that you wan to walk off automatically (walkable Area 1), and one surrounding it which represents where you want to walk off the region onto (as well as the entire walkable area in itself)... Walkable area 2.

So what you do is this:

First you call:

Code: ags

RemoveWalkableArea(1); // this will stop the walkable area over the region your character is on 
//from being a walkable area. To help us find out where the closest walkable area is now that's not an option...

// Then move your dummy invisible character to the place your character is...
cInvis.x = cPlayer.x;
cInvis.y = cPlayer.y;

// Since the walkable area they're stood on no longer exists, if you call:
cInvis.PlaceOnWalkableArea();

// It should, in theory, move the invisible character to the closest pixel that's on a valid walkable area using 
// CJ's closest point code now that the disabled region is not an option. Then do...

RestoreWalkableArea(1); // This should reinitialise the walkable area the player is stood on so he can walk on it freely again.

// Then finally, you make the player walk to wherever the dummy character was moved to:
cPlayer.Walk(cInvis.x, cInvis.y);


This should, in theory, always work out the closest point to where he is stood out of the region. might be overkill, I dunno. :)

Hope this helps!

lemmy

Goldenrod111

cInvis works! It's moving the player slightly to the side, but he is moving off the region! Thanks, lemmy101! Thanks for the sugestion, Rui 'Trovatore' Pires! By the way, how can I put the "(Solved)" in the thread title?

lemmy101

#4
Quote from: Goldengamer111 on Sun 23/03/2008 17:24:30
cInvis works! It's moving the player slightly to the side, but he is moving off the region! Thanks, lemmy101! Thanks for the sugestion, Rui 'Trovatore' Pires! By the way, how can I put the "(Solved)" in the thread title?

"It's moving the player slightly to the side" Are you sure this is the best solution then? and cInvis isn't the same character you're trying to move? I didn't think there would be any visible snap of the player using this as all the player does is walk to a location, it's the invisible character that's snapped to the walkable area.

You could try adding a cPlayer.StopMoving(); before all that code, it might stop him snapping.

If you're happy with the results though, then cool. :) glad to help!

PS: Click Edit Topic and then edit the subject.


Goldenrod111

I meant that the player walks to the side (facing the way he's going) as well as getting off the region, smoothly. Sorry if I confused you

P.S. Where is "Edit Topic"? At the top (were I would expect it to be), it just says "Reply | Notify of replies | Send this topic | Print".

nihilyst

Quote from: Goldengamer111 on Sun 23/03/2008 18:18:57
P.S. Where is "Edit Topic"? At the top (were I would expect it to be), it just says "Reply | Notify of replies | Send this topic | Print".

Editing the topic of your first post should do it.

lemmy101

Ahh it's actually called "Modify", sorry. :)

Glad it worked! :)

lemmy

SMF spam blocked by CleanTalk