My character faces backwards when he goes into new room

Started by MonkeysMightBeFun, Thu 07/08/2014 00:54:22

Previous topic - Next topic

MonkeysMightBeFun

So basically I have a staircase, and my character walks up it to get to the other room. The problem is, since he faces backwards to walk up he stays backwards when he gets to the other room. It looks tacky. How would I go about making him face forward when he appears in the next room?

Mandle

Quote from: MonkeysMightBeFun on Thu 07/08/2014 00:54:22
So basically I have a staircase, and my character walks up it to get to the other room. The problem is, since he faces backwards to walk up he stays backwards when he gets to the other room. It looks tacky. How would I go about making him face forward when he appears in the next room?

Choose the lightning bolt mark next to "Enters room before fade-in" in the Edit Room window of the room the character appears facing the wrong way in. (This makes sure that the player won't see the character turn around. It will happen before the room appears on the screen.)

Put in that function in the room script the code:

cEgo.FaceLocation(1000, 400, eBlock);

Change cEgo to your character's script name and the 1000, 400 to whatever location you want him to face.

A few pixels left or right of his starting location should be fine depending on which way you need him to face.

A new problem you will now have is that no matter what entrance your character comes through into that room the script will make him face the location you chose.

You can fix this with assigning a global bool variable for when the player leaves the stairs room. Something like "CameFromStairs" and set it initially to "false".

As the player leaves the stairs room set it to:

CameFromStairs = true;

So then the previous code I mentioned will be:


if (CameFromStairs == true)
   {
   cEgo.FaceLocation(1000, 400, eBlock);
   CameFromStairs = false;
   }


There may be easier ways to do this, but I think mine should work fine (code untested)

EDIT: I just realised that it's probably easier to just test the character's location after he enters the room, in "Enters before fade-in" instead of using a Global Variable. If the character is in the location after coming from stairs room then the FaceLocation script runs... :-[

MonkeysMightBeFun

#2
Works wonderfully! Perfect!

Oh, I see.
It seems that when I try to type in "camefrom" nothing comes up? Is it only for some versions of AGS?

Mandle

Quote from: MonkeysMightBeFun on Thu 07/08/2014 01:07:51
Works wonderfully! Perfect!

Oh, I see.
It seems that when I try to type in "camefrom" nothing comes up? Is it only for some versions of AGS?

You have to define a new Global Variable in the Global Variable screen first.

Choose a bool variable, name it "CameFromStairs" (or whatever you like...I just find that naming variables to remind me what they do is very helpful when you start to accumulate a lot of them) and set starting value to "false".

Now, because it is a Global Variable you can call on it in any script in your game and AGS will recognise it.


Mandle


Khris

You can simply check player.PreviousRoom.
Code: ags
function room_Load()
{
  // if entered from room 3, face right
  if (player.PreviousRoom == 3) player.FaceLocation(player.x + 1, player.y);
}


While the bool method will work just fine for other stuff, it's important to keep in mind to not just set it to true but also to false. And when dealing with multiple exclusive conditions, it's better to use a single integer variable instead of multiple bools.

AnasAbdin

Khris' method is my usual solution in addition to an extra condition since I can have multiple entrances to a room.

Mandle

Quote from: Khris on Thu 07/08/2014 03:11:07
You can simply check player.PreviousRoom.
Code: ags
function room_Load()
{
  // if entered from room 3, face right
  if (player.PreviousRoom == 3) player.FaceLocation(player.x + 1, player.y);
}


While the bool method will work just fine for other stuff, it's important to keep in mind to not just set it to true but also to false. And when dealing with multiple exclusive conditions, it's better to use a single integer variable instead of multiple bools.

Pwned by Khris once again!

But...I think I did remember to set it back to "false" in my "advice" code...

I am in contact with this person so I will now send him a mail saying the correct solution has been reached...


Slasher

Hi

maybe there is something I'v missed (roll)

what about:

Code: ags

 if (player.PreviousRoom == 3) 
 player.Loop=2; // Face Right
 else if (player.PreviousRoom == 4)
 player.Loop=1; // Face Left
 // etc etc....



Khris

Quote from: Mandle on Thu 07/08/2014 06:05:19But...I think I did remember to set it back to "false" in my "advice" code...
If you did, I haven't seen it. You only said to init it to false. The problem here is that entering the room via another exit must set, say, CameFromDoor to true, while also setting CameFromStairs to false. Otherwise, if the player came from the stairs at some earlier point, the before fadein code will determine the player came from the stairs even when they didn't.

Mandle

Quote from: Khris on Thu 07/08/2014 16:12:22
Quote from: Mandle on Thu 07/08/2014 06:05:19But...I think I did remember to set it back to "false" in my "advice" code...
If you did, I haven't seen it. You only said to init it to false. The problem here is that entering the room via another exit must set, say, CameFromDoor to true, while also setting CameFromStairs to false. Otherwise, if the player came from the stairs at some earlier point, the before fadein code will determine the player came from the stairs even when they didn't.


if (CameFromStairs == true)
   {
   cEgo.FaceLocation(1000, 400, eBlock);
   CameFromStairs = false; <---------------------here...I think?
   }


0% sarcasm here...

I know my fix was useless compared to yours...I did not know the PreviousRoom code but know it now...

The only reason I continue to reply is to learn.

From what I understand of coding I think my clumsy advice would have still maybe worked.

If there is a reason why my Global Variable of CameFromStairs = false; was out of place in the "Load room before fade in" script?

I understood what you said about the player entering from a different room and the variable still having not been reset to "false"...

I'm just interested in learning why my code wouldn't have done that.

Not trying to be faecious here

Khris

Sorry, I didn't see that before now. Your advice/code is completely fine and would be the next best solution if there were no way of determining the previous room.

Mandle

Quote from: Khris on Fri 08/08/2014 17:18:29
Sorry, I didn't see that before now. Your advice/code is completely fine and would be the next best solution if there were no way of determining the previous room.

Code: ags

Cheers Khris...
Now if only I had learned how to do the code-in-posts thingy eh?

SMF spam blocked by CleanTalk