9 Replies Latest reply on Aug 25, 2006 10:54 AM by extol

    Hm this is gonna be a tough one..

    Pelleyoo Level 1
      Have you guys ever played a game named Grim Fandango? Properbly not. Anyway, we are doing a game smiliar to Grim Fandango, which means its a 3d adventure game. We've come up with some really clever solutions for the game mechanics, but now the source is getting so complex that we feel that we want to "split up" the code into different behaviors with different names.

      For example, when the character enters a specified area, "Trigger_talk_bartender", we want a behavior to get activated. This behavior will control the characters motions, overlay-text and if the current line is to be played over and over again or if a new line is to be played the next time the player enters this area.

      Every conversation will have its own "Talk behavior". But how should we get them to work together? Maybe something like this?;

      If char.position = Trigger_talk_bartender then
      Go Talk_Behavior_1 me
      end

      and then the behavior will be "On Talk_Behavior_1 me".

      Its so complex to explain but I hope you understand everything and go help me with problems.
        • 1. Re: Hm this is gonna be a tough one..
          extol Level 1
          Hi, Pelleyoo. I actually have Grim Fandango, although I haven't played it in years. I never thought about handling each character interaction with a different behavior. But definitely is a way to go. As far as the code you wrote, that would definitely work. But it mighty be best to do a list (array) of possible conversations like so:

          repeat with j = 1 to interaction_behaviors.count -- cycle through the list of possible interactions
          if char.position = interaction_behaviors[j].position then -- if our character is ready to interact with this person
          do interaction_behaviors[j].myBehavior -- execute the behavior that handles this conversation
          exit repeat -- and stop the cycle
          end if
          end repeat

          Then for each interaction, you could set up an behavior in the list:

          add interaction_behaviors, [#position: vector(100, 120, 10), #myBehavior: "bartender_talk()"]

          So when your character gets to 100, 120, 10 (xyz coordinates), it would trigger the bartender_talk behavior

          on bartender_talk me
          -- The bartender will say something cool
          end


          I hope this helps. One thing to note is that you will want to change that first line
          if char.position = interaction_behaviors[j].position then

          to some sort of function (which you would write) that checks to see if your character is in the vicinity of the bartender, not the exact position
          if checkProximity(me, char.position, interaction_behaviors[j].position) then


          Good luck with this project!
          • 2. Re: Hm this is gonna be a tough one..
            Roofy Level 1
            Hi Pelleyoo,

            I do not understand why you did not animate the characters in your 3D application. What I would of done is created animamations in my 3D application, and then depending on if I was animating the charcter by its bones, then I would use the bones player modifier, or if I was animating the character through keyframes, then I would use the keyframe player modifier. However, no matter which modifier I did use, both of them allow you to put your animations into a play list que as well as blending one anitmation into the next animation that is in the play list que.

            In addition, to make things easier for me when coding the script, I would also create an invisible object such as a door for a doorway that when the collision detection hits the invisible object, then the script would know the user has entered a certain room. Once the script knows that the user has entered that piticular room, then I would have the script call a "sendSprite" command. The arguments for a sendsprite command is as follows...

            sendSprite(to which sprite you want the message to be sent to, #messageHandler, your additional arguments)

            for example, the beliow script will send the message playMe to sprite 0, which is the frame script behaviour area, and also send the argument of the motion's name "Speek", and which character is suppose to speek

            on collisionDetected collisionData
            if collisionData.name = "BarRoom" then
            sendSprite(0, #playMe, "speek", "barTender")
            end if
            end collisionDetected

            ... this line of code is part of the behaviour script that lies on the frame behaviour script....

            on playMe me, motName, CharName
            notLooped = 0
            startTime = 0
            endTime = 60000 -- this is in milliseconds which 60000 milliseconds is equaled to one minute
            member("my3dScene").model(CharName).bonesPlayer.play(motName, notLooped, startTime, endTime)
            end playMe
            • 3. Re: Hm this is gonna be a tough one..
              extol Level 1
              Hi, Roofy. That is a good point. I assumed that Pelleyoo had already made the character animations in his 3d app. If not, Pelleyoo, I agree with Roofy that you should do so. But, I think what Pelleyoo is talking about is handling interactions. In Grim Fandango, you were given several lists of questions/responses in each conversation that you could select to say. Then the character you are conversing with would be animated and speak differently depending on which question/response you picked. So there are dozens of animations for each character. So I think Pelleyoo wants to seperate each conversation in a separate behavior so that it's cleaner for the programmers. So the behaviors would tell the model what animations to show and when, depending on what the user did. Then use bonesPlayer.play to show the appropriate frames of animation. Maybe I am wrong, but that's what I was thinking.
              • 4. Re: Hm this is gonna be a tough one..
                Pelleyoo Level 1
                Extol, you've got it right on spot. I haven't tried the method you recommended, yet, but it makes sense to me and I will report how it went tomorrow when i've tried it.
                • 5. Re: Hm this is gonna be a tough one..
                  Newt99 Level 1

                  I also have bought and played Grim Fandango at the time !

                  You can use sendSprite() indeed if you want to target just one specific sprite or use sendAllSprites() if you want to send the message to all behaviors.

                  You can use the scriptInstanceList of a sprite in order to dynamicall assign behaviors to it.

                  Best regards,
                  Karl.

                  http://www.chromelib.com
                  • 6. Re: Hm this is gonna be a tough one..
                    Pelleyoo Level 1
                    Well Extol. We just want to know really how ones own behaviors can be attached to a sprite with an internal code already haved.

                    For example, you can attach as many chrome lib behaviors a member as you want. But i dont know how to attach my own behaviors. As you understood extol, this will only be for make the code simple and sliced. thats what we want to have. it would makes us glad


                    Thanks on beforehand
                    • 7. Re: Hm this is gonna be a tough one..
                      Level 7
                      Well Extol. We just want to know really how ones own behaviors can be attached
                      to a sprite with an internal code already haved.

                      For example, you can attach as many chrome lib behaviors a member as you want.
                      But i dont know how to attach my own behaviors. As you understood extol, this
                      will only be for make the code simple and sliced. thats what we want to have.
                      it would makes us glad


                      Thanks on beforehand

                      • 8. Re: Hm this is gonna be a tough one..
                        Newt99 Level 1

                        You have two solutions:

                        - The first is the one I told about previously, i.e using the scriptInstanceList of the W3D sprite in order to dynamically attach as many behaviors as you want to it.

                        - Add the standard handlers in your own behaviors like getPropertyDescriptionList() or is3D(). Just have a look either at the Chrome Lib behaviors or at the standard 3D behaviors. You will see they all use a small set of handlers that are the same. These are looked for by Director when you drag'n'drop a behavior onto a sprite. If they are not there, you cannot assign the behavior to the sprite.

                        Cheers,
                        Karl.
                        • 9. Re: Hm this is gonna be a tough one..
                          extol Level 1
                          Click on your sprite in the score. In the Property Inspector window to the right, click the Behaviors tab. Click the plus sign to make a new behavior. Name it what you want. it will then appear in the list. Right click it and then select "script". Then you can add your script. This behavior will now be in the cast window as well. So if you need to attach that behavior to any other sprites, just drag it onto them from the cast. If you want a window that gives you paramaters to enter when you attach the behavior, you need to use getPropertyDescriptionList(), like Newt99 mentioned. Good luck!