Follow a character after a chat.

TWEAmazingAppsTWEAmazingApps Member Posts: 219
edited February 2012 in Working with GS (Mac)
Hi I am working on script right now. where the Main Character gose up and speaks to a NPC and after the talk the NPC follows the Main Character.

Here are the Custom attributes I made.
ActorX: Real
ActorY: Real
Follow: boolean

((ActorX,ActorY is constrained to the main characters X,Y.))

Here is how I made it for the NPC.
RULE: If Follow is True
Then
RULE: When self.position.X doesn't = ActorX & self.position.Y doesn't = ActorY
Move To: ActorX, ActorY

And for the TextBox (Where the conversation is displayed.
I made the "Follow"Attribute To True to active the NPC rule.
(Ill do Sudo Code cuz if I type it it will be to much XD))

Rule: When page = 2 (means when the last page say page 2of2 is opened)

Change Attribute: Follow To True.

So After he reads the last page the NPC will follow.

So the main character finishes the conversation.
And it works!The NPC moves to the character but then after the NPC reaches the Main Characters
Position the NPC doesn't move after that. IT only gose to what ever position the Main character is and once its X,Y reaches it. It will just chill there. Dose anyone know how I can fix this or is there a better way to do this? I thought maybe its only True when the last page of the conversation is opened so maybe its being set to false again so I talked to the NPC again and go
through to the last page and the NPC wont move. :/ I hope you guys can understand this.

Comments

  • AppsterDudeAppsterDude Member Posts: 84
    Try to use Interpolate.
  • simo103simo103 Member, PRO Posts: 1,331
    @TWEAmazingApps .. I wouldn't use Interpolate as it is a dominate behaviour and will not likely update itself to move after your Main Character but will move to its old position first. Move to is correct in my opinion. Because your rule is to move only if X AND Y are not the same as the MC Actor .. is it possible that you move the MC Actor away from the NPC but either the X or Y is still the same? IE if you moved on the X axis (since the Y is teh same then teh move to wouldn't trigger?)

    If you are moving the MC actor away and it is on different X and Y and still no move .... I would drop a display text in the NPC to show the Follow rule to make sure it is true at all teh right times. If that all seems correct come back and post again and I'll see if I can give more ideas.
  • TWEAmazingAppsTWEAmazingApps Member Posts: 219
    @ryguy140 Use interpolate instead of change attribute? I did try that and it will follow and then once it reaches the Main Characters x,y position then he stops once again.
  • TWEAmazingAppsTWEAmazingApps Member Posts: 219
    edited February 2012
    @ryguy140 I used the Interpolate So wrong But I did try it out but that didnt even work right. (Tho to be honest I never ever ever used interpolate so I didnt know what it did I read the description and threw it in Xd) @simo103 I use the MoveTo since the beginning and it worked when I didn't have the rule set up yet. I first wanted to make the NPC follow the MC first before I made a rule. I did this to see if I got the scripting right so I know I made it correctly. Then I added the Rules and that's where I failed life. It seems that when I speak to the NPC he will follow then stop. So I added a timer to it so after 3 second active the follow To True so I controlled the MC and ran away from the NPC to see if he would stop only at the X,Y of the MC when it started to move. It didnt stop it actually kept following me till it reached my MC then once it finally aligned itself to the X,Y(When I finally stopped moving XD) IT stopped after that.Thanks guys for the help ouT!
  • FallacyStudiosFallacyStudios Member Posts: 970
    edited February 2012
    Well depending on what exactly it should look like. You could always do a constrain attribute for the NPC. So when follow is true constrain attribute to ActorX-50 or something like that. That would have him following behind. You can always modify off that if your guy can go the other direction by having some rules that handle the exceptions.

    It really depends on the game. I'm not sure if it is a side scroller or open map. If you want him following at exacts or at a rubber band distance (meaning he can follow behind some or get closer)
  • TWEAmazingAppsTWEAmazingApps Member Posts: 219
    Sorry bought the I just made I had to edit I saw my typing didn't make sense ha..
  • TWEAmazingAppsTWEAmazingApps Member Posts: 219
    @FallacyStudios Its a underwater side scrolling game so he can swim up and down left and right :) Ill give it a shot. I am just trying things to see if I can get abit closer to my goal. Thanks !
  • TWEAmazingAppsTWEAmazingApps Member Posts: 219
    @simo103 So here is what I did. I made a small debug rule to see if the Rules I made are working. I made a "New Actor" And made a rule in it the display one you said to do. This is what I put. Rule: If "Follow is "False"
    Display Text: YOUR FALSE! Otherwise: Rule If "Follow" Is true then DisplayText:YOUR TRUE!!!
    And....It worked it was false until I finished speaking to him then the NPC followed me for a second and then stopped when it reached my x,y. But If I put a Timer on him 3 seconds later he will follow me and Ill run around for abit then stop once he catches up to me and matches my x,y then He stops so the follow Kind of works still. I saw the the Display Text Stayed at YOUR TRUE! so it didn't go back to false.... I got confused after that. I thought that is whats going on but now. I don't know whats the deal.
  • FallacyStudiosFallacyStudios Member Posts: 970
    @TWEAmazingApps

    Well the way I explained previously could work, it would work better for a side scroller.

    I haven't tested this, but you could possibly try a range. Make a rule inside the NPC for when follow is true with a rule inside that says ANY self.positionX is <= game.ActorX-20 OR self.positionX is >= game.ActorX+20 OR self.positionY is <= game.ActorY-20 OR self.positionY is >= game.ActorY+20

    (It would be an ANY rule)

    Then

    It Moves To Actor X,Y

    You may need to adjust the 20's to something that fits the distance range away from your character that you will allow. This should make it so that if your character gets a certain distance from the NPC the NPC will head to his location. It should do the Move To each time because the rule should be calling it everytime one of those matches up right.

    Hopefully that gets you what you are looking for
  • FallacyStudiosFallacyStudios Member Posts: 970
    edited February 2012
    @TWEAmazingApps

    Going off your last comment. The problem is most definately Move To. Move To works up until the actor reaches the points it is supposed to Move To. Then it no longer does anything. That's why in my explanation above I put it inside of a rule that should cause him to Move To the location each time the rule meets the requirements.
  • TWEAmazingAppsTWEAmazingApps Member Posts: 219
    @FallacyStudios Thanks Ill give it a shot right now.
  • TWEAmazingAppsTWEAmazingApps Member Posts: 219
    @FallacyStudio
    Going off what you just said. That leaves me in another puzzed thought. Because if I take away the rule I have the If Follow is True. Then The NPC will follow me everywhere I go and When I stop and he matches my x,y and I move again he will still follow. I didn't get this problem until I got the rule going. Which is odd. But I am going to give it a go on what you posted earlier. Thank you!
  • FallacyStudiosFallacyStudios Member Posts: 970
    edited February 2012
    @TWEAmazingApps

    Well I'm pretty sure Move To works all the way up until it is completed. So basically you want inside that NPC:

    -Rule If Follow is true
    -Rule Inside The Above Rule That tests whether the NPC is a certain distance away from the Actor (the code bit in my previous post would go here)
    -The Move To inside the above testing rule.

    This should make it so the NPC moves to where your actor is each time your actor moves a certain distance away from him and as long as follow is true.

    If at any point you make follow not true he should stay in the last location reached.

    If the NPC is already in the process of doing a move to because your actor has moved and Follow is switched to false in the process. I'm pretty sure the NPC will continue until your completes the Move To

  • TWEAmazingAppsTWEAmazingApps Member Posts: 219
    @FallacyStudios Alright I am giving it a go. IN the Rule you made is it Laid out like this?
    Rule: if game.Follow is true
    Then
    Rule:
    Attribute: self.Position.X < game.ActorX-20
    Attribute: self.Position.X > game.ActorX+20
    Attribute: self.Position.Y < game.ActorY-20
    Attribute: self.Position.Y > game.ActorY+20

    MoveTo game.ActorX, game.ActorY
    Its how I made it.It seems to not be working out for me. NPC not moving now. Did I lay it out correctly
    Or did I do something wrong.
  • TWEAmazingAppsTWEAmazingApps Member Posts: 219
    edited February 2012
    @FallacyStudios Actually I correct myself. It seems I was in wrong I did not put the Rule with the Attributes to Any. You solution worked!! Thank you very much for the help for it worked very well and is exactly what I wanted to be like.
  • CloudsClouds Member Posts: 1,599
    "Follow a character after a chat."

    Always tell your parents first.
  • FallacyStudiosFallacyStudios Member Posts: 970
    @TWEAmazingApps

    Not a problem. Glad to help and that it worked.
  • TWEAmazingAppsTWEAmazingApps Member Posts: 219
    edited February 2012
    @Simo103 @FallacyStudios @ryguy140 Thank you guys for your help and taking the time to help me out with my codeing. I got my answer from @FallacyStudios . He/she (dont know gender) figured out my problem and helped me out to get it to work! Again I thank you You guys have a wonderful day...or night!
  • TWEAmazingAppsTWEAmazingApps Member Posts: 219
    @Tynan funny...
  • simo103simo103 Member, PRO Posts: 1,331
    @TWEAmazingApps .. no problem .. glad to try and help and glad you got it going with FallacyStudios help.
  • FallacyStudiosFallacyStudios Member Posts: 970
    @TWEAmazingApps

    FallacyStudios = He :) lol
Sign In or Register to comment.