SOLVED: Separating The Main Character Into Two

Started by stepsoversnails, Sun 20/03/2011 11:03:29

Previous topic - Next topic

stepsoversnails

I not sure if what i want is a simple matter or not.
basically i want to have a button that when pressed makes the main character do a little animation where he splits into two and then the other half be controllable.
I know that the button that makes him animate is at least possible but having the new character show up exactly where he was when the separating animation ended, i figured to be a little more complicated (but hopefully it's not).
here is a picture, if it will help you understand.

ThreeOhFour

This is totally possible! One way of doing it would be like this:

Have a seperate view that just contains the body sprite, and assign that to a character such as cBody. Have another seperate view assigned just to the head view. When you click the button, have the cBody character appear in the room at player.x and player.y, switch player's view to the head view, and run the animation. Depending on how you import your sprites, you may need to adjust the player's position as well.

The best way to make sure your sprites line up is to make the canvas for all of them quite large, with the sprites in the very centre. AGS centres player sprites, so no matter the width of your canvas, the sprite will always be in the middle for a character, making it easy!

Hopefully this makes sense :)

stepsoversnails

that does make sense but i'm still struggling with having the characters showing up were they're supposed to and not jumping around the place.
also i'm having trouble with the actual scripting.
thanks though.

stepsoversnails

really i just need to know how i should script it to make the character appear a certain distance infront of the old character and how to script it so the new character always appears in the same room as the old character.

TomatoesInTheHead

Er, something along the lines of this?

Code: ags
cHead.ChangeRoom(cBody.Room);
cHead.x = cBody.x - 50;


Where 50 is the distance and should be the same as the distance where the animation ends.


And I like the idea of separating body parts, hope to see the finished game with this feature! :)

stepsoversnails

oh thanks.
i got it to work up until the new character enters the room.
instead of him entering in front the player where the animation ends, he instead shows up at his start x and y, that is specified on his character properties.

stepsoversnails

wait.
nevermind.
i just rechecked it and added the y axis to the code.
it works great now.
thank you all so much for your help!

stepsoversnails

okay one last tiny little thing.
I think it's a problem with how i've scripted it.
But to ensure that the character can't be spawned onto an area he not allowed to walk on i've wrote a little script to check for walkable areas around him.
The weird thing is that it works when he is on the left side of the room but not the right.

Code: ags
 if (GetWalkableAreaAt(cEgo.x - 40, cEgo.y + 20) == 0){
   Display ("There's not enough room here.");
}
  else if (GetWalkableAreaAt(cEgo.x + 40, cEgo.y + 20) == 0){
   Display ("There's not enough room here.");
   } 
else {
                    cEgo.LockView (VIEW5); 
                    cEgo.Animate (2, 3, eOnce, eNoBlock, eForwards);
                    cChar1.ChangeRoom(cEgo.Room);
                    cChar1.x = cEgo.x - 0;
                    cChar1.y = cEgo.y - 0;
                    cChar1.LockView (VIEW4);
                    cChar1.Animate (2, 3, eOnce, eBlock, eForwards);
                    cChar1.UnlockView ();
                    cChar1.SetAsPlayer ();
                    gGui1.Visible = false;
                    cEgo.Clickable = true;
                    
  }
      }

mode7

Is this a scolling room? bacause if it is you would have to put:
(GetWalkableAreaAt(cEgo.x.GetViewportX() - 40, cEgo.y-GetViewportY() + 20) == 0){

stepsoversnails

that sounds like it should work but whenever i put it in AGS comes up with an error telling me there is no function called GetViewport.
I've looked for the function on the wiki and i can't find it there either.

TomatoesInTheHead

Don't forget the X and Y, it's part of the function name ;)

(Though I would expect the wiki search to find also the partial name, but as I see, it doesn't. GetViewportX() and GetViewportY() are described here)

stepsoversnails

thank you for that.
But it doesnt appear to be working.
the only way i could ags to accept the script as to change it from
Code: ags
(GetWalkableAreaAt(cEgo.x.GetViewportX() - 40, cEgo.y-GetViewportY() + 20) == 0){

to
Code: ags
(GetWalkableAreaAt(GetViewportX() - 40, GetViewportY() + 20) == 0){
   Display ("There's not enough room here.");


but now it just seems to skip the first part of the script and go straight to saying There's not enough room here.

stepsoversnails

okay i've now changed it to this.
Code: ags
if (GetWalkableAreaAt(cEgo.x-GetViewportX()+40 ,cEgo.y-GetViewportY()+20==0)){
   Display ("There's not enough room here.");

and he can switch characters on the other side of the room (which was a scrolling room).
but now he can't detect the ends of walkable areas.
any suggestions?

mode7

what do you mean by "ends"?
Are you still doing it for ...x+20... and x-20...

stepsoversnails

im using the getViewport function.
and by ends i just mean where there are no walkable areas.

TomatoesInTheHead

I guess you have a misplaced parentheses there:
Quote from: stepsoversnails on Mon 21/03/2011 09:32:16
if (GetWalkableAreaAt(cEgo.x-GetViewportX()+40 ,cEgo.y-GetViewportY()+20==0)){
   Display ("There's not enough room here.");

It should be:
Quote
if (GetWalkableAreaAt(cEgo.x-GetViewportX()+40 ,cEgo.y-GetViewportY()+20)==0){
   Display ("There's not enough room here.");


Otherwise the boolean expression "... == 0" is interpreted as an integer (0 or 1), and the result of the GetWalkableAreaAt() function is interpreted as a boolean (zero = false, non-zero = true) in the if statement.

stepsoversnails

oh my gosh.
all i was missing was one little bracket!?
ahaha. I'm stooopid.
sorry about that guys.
it works perfectly now.
thank you for the help.

SMF spam blocked by CleanTalk