8 Replies Latest reply on May 21, 2009 1:39 AM by DAVID NAJAR

    My Game Needs HELP!

    greek_dude247

      My programming skills have hit its max and I need some of your godly lingo skills. In Level1 (after tutorial level) I have a river. The player is stuck at dock1 and you need to get to dock2 at the end of the river. But the player isn't allowed to enter the water. There is a piece of drift wood floating down (from dock1 to dock2 to the end- waterfall) and the player has to step on the driftwood. It would would then take the character with it. What the player must do is step off the drift wood right when it is close to dock2. Otherwise the driftwood goes over a waterfall which would kill the player.

       

      So David said that there's an .addChild property. Something like

       

        pObject.addChild(pCamNull,  #preserveWorld)
       
      What I had mind is...

       

      Body would always check down and attach itself to whatever is below it. When "W" is pressed, it would be released form the object below it, thus letting the player move. So that way, the player would have to stand on the drift would and wait till its time to release him/herself from it onto the dock.

       

      Do you kind of get what I had in mind? You don't have to do it that way that's just what my thought was about how it'd work.

        • 1. Re: My Game Needs HELP!
          DAVID NAJAR

          Hi,

           

          It sounds like an old Frogger Atari game (ok I think yours is a 3D one). There's no easy answer becouse what you are trying to do generally is based on a collisions system (detection and response). When you start a new project you have to build all your game around such system from its base and is too hard to implement on final production stages.

           

          Basicly there're three options to do that:  Dynamiks Xtra, Collision Modifier or your own code for collisions. These solutions have their pros and cons and the less useful is the Collision Modifier for its huge performance impact. It left just two practical options, Dynamiks Xtra where you have to rewrite all your movements code at least, and the last one, write your own collision system with all the hard work it represents.

           

          Seems these options doesn't satisfy your current needs, then I just can  recomend to you about your solution: "Body would always check down and attach itself to whatever is below it" ?.

           

          Yes, it is possible to verify constantly which models are below your player character and react according that. You can use modelsUnderRay()(check help for command use). You have to define a location vector (maybe near your player character's center feet), a direction vector (maybe a down vector like vector(0,-1,0)) and a options list (maybe a detailed one). This method returns useful info about models fund by your ray, then use addChild() or myNode.parent = to attach one model to the other, or just copy on each loop the moving platform position to your player character position. You can also use _key.keyPressed() to break the parenting behavior or do whatever you need.

           

          Could be lots of implementations for what you are trying to do, So use this info just as starting point.

           

          Have a nice day.

           

          DN

          1 person found this helpful
          • 2. Re: My Game Needs HELP!
            greek_dude247 Level 1

            Thanks David,

             

            So I do have a collision detection code. I was planning on using the ray its shoots under the player to check the model under it. I guess I'd have to have some sort of condition saying

             

                     if body isn't moving add.child  (model below)

             

            is that right? and then:

             

                      if a button is pressed, release child from model

             

            thus allowing the player to move.

            I could post a sample of the collision code if it would help. I kind of got stuck with programming on this game so I don't know really where to start with the lingo syntax.

             

            Anyway, if you don't know what to do thank you so much for your post. I will post a link to the game once its done and I hope this mechanic will be in the final product.

            • 3. Re: My Game Needs HELP!
              DAVID NAJAR Level 1

              Hi again,

               

              I think it could be more ease, you just have to check the model below your player character and if the model's name meets some predefined labels then parenting your player's model with it.

               

              You dont have to be parenting the model all the time, just do it for stage moving models, becouse if your floor doesn't move there's no reason to parenting your model, and when your player's model is a child of other model all changes in positions by default are relative to its parent.

               

              Maybe the pseudo code could be:

              my player character STEP is 5 units
              if user press "W" key then
                   get the NAME of the model below my player one STEP in front
                        if the NAME contains “drift” and NAME is different to the CURRENT_NAME below then
                             my player parent is WORLD preserving current position
                             move my player one STEP in front
                             my player parent is model named  NAME preserving current position

                             CURRENT_NAME is NAME
                        if the NAME doesn’t contains “drift” then
                             move my player one STEP in front

                   end get the NAME of the model below

              end if user press “W”

               

              If you want a working sample code please post a sample of yours to try to provide a solution.

               

              Have a nice day!

               

              DN

              • 4. Re: My Game Needs HELP!
                DAVID NAJAR Level 1

                Hi,

                 

                I code a speed working sample for you, it is a frame behavior. Just copy & paste de code to a new script behavior, drag & drop the behavior to the timeline on frame 1, insert a new blank Shockwave 3D member and put it on sprite (channel) 1, run the movie. Use WASD keys to move the player. Is not the most elegant code! Is just a speed basic guide.

                 

                I hope this can help you.

                 

                Have a nice day!

                 

                DN

                 

                 

                ---------------------------------------- CODE --------------------------------

                property pw3dMember
                property pPlayerStep
                property pStep
                property pPlayerModel
                property pFloorModel1
                property pFloorModel2
                property pDriftWoodModel1
                property pDriftWoodModel2
                property pDriftWoodModel3
                property pDriftWoodActorsList
                property pOptionsList
                property pDirectionVector
                property pCurrentBelowModelName

                 

                on beginsprite(me)
                  pW3DMember = sprite(1).member
                  pW3DMember.resetWorld()
                 
                  pPlayerStep = 1
                 
                  vmrFloor= pw3dMember.newModelResource("mrFloor", #plane)
                  vmrFloor.length = 50.0000
                  vmrFloor.width = 275.0000
                  pFloorModel1 = pW3DMember.newModel("floor_1", vmrFloor)
                  pFloorModel2 = pW3DMember.newModel("floor_2", vmrFloor)
                  pFloorModel1.transform.position = vector(0.0000,-52.0000,0.0000)
                  pFloorModel2.transform.position = vector(0.0000,52.0000,0.0000)
                 
                  vmrDriftWood= pw3dMember.newModelResource("mrDriftWood", #plane)
                  vmrDriftWood.length = 18.0000
                  vmrDriftWood.width = 50.0000
                  pDriftWoodModel1 = pW3DMember.newModel("driftwood_1", vmrDriftWood)
                  pDriftWoodModel2 = pW3DMember.newModel("driftwood_2", vmrDriftWood)
                  pDriftWoodModel3 = pW3DMember.newModel("driftwood_3", vmrDriftWood)
                  pDriftWoodModel1.transform.position = vector(-112.0000,-18.0000,0.0000)
                  pDriftWoodModel2.transform.position = vector(112.0000,0.0000,0.0000)
                  pDriftWoodModel3.transform.position = vector(0.0000,18.0000,0.0000)
                 
                  vmrPlayer= pw3dMember.newModelResource("mrPlayer", #sphere)
                  vmrPlayer.radius = 5
                  pPlayerModel = pW3DMember.newModel("player", vmrPlayer)
                  pPlayerModel.transform.position = vector(0.0000,-50.0000,3.0000)
                 
                  pDriftWoodActorsList = []
                  pDriftWoodActorsList.append( [#model: pDriftWoodModel1, #speed:1.0, #direction: 1])
                  pDriftWoodActorsList.append( [#model: pDriftWoodModel2, #speed:1.5, #direction: -1])
                  pDriftWoodActorsList.append( [#model: pDriftWoodModel3, #speed:2.0, #direction: 1])
                 
                  pOptionsList = [#maxNumberOfModels: 1, #levelOfDetail: #simple]
                  pDirectionVector =  vector(0.0000, 0.0000, -1.0000)
                  pCurrentBelowModelName = ""
                end

                 

                on exitFrame(me)
                  me.playerMove()
                  me.moveDriftWood()
                  _movie.go(_movie.frame)
                end

                 

                on playerMove(me)
                  vCurrentPlayerPosition = pPlayerModel.worldPosition
                 
                  vStepX = vCurrentPlayerPosition.x
                  vStepY = vCurrentPlayerPosition.y
                 
                  if _key.keyPressed("w") then vStepY = vStepY + pPlayerStep
                  if _key.keyPressed("s") then vStepY = vStepY - pPlayerStep
                  if _key.keyPressed("d") then vStepX = vStepX + pPlayerStep
                  if _key.keyPressed("a") then vStepX = vStepX - pPlayerStep
                 
                  vTargetLocation = vector(vStepX, vStepY, vCurrentPlayerPosition.z)
                 
                  vModels = pW3DMember.modelsUnderRay(vTargetLocation, pDirectionVector, pOptionsList)
                 
                  if vModels.count then
                   
                    vFloorModel = vModels[1]
                    vFloorModelName = vFloorModel.name
                   
                    if  pCurrentBelowModelName <> vFloorModelName then
                      pPlayerModel.parent = vFloorModel
                      put "Changing dynamic parent to model:" && vFloorModelName
                    end if
                   
                    pPlayerModel.worldPosition = vTargetLocation
                    pCurrentBelowModelName = vFloorModelName

                 

                  end if
                end

                 

                on moveDriftWood(me)
                  repeat with i = 1 to pDriftWoodActorsList.count
                    vCurrentPosition = pDriftWoodActorsList[i].model.transform.position.x
                    if  vCurrentPosition > 112.0000 then pDriftWoodActorsList[i].direction = -1
                    if  vCurrentPosition < -112.0000 then pDriftWoodActorsList[i].direction = 1
                    pDriftWoodActorsList[i].model.transform.position.x = vCurrentPosition + (pDriftWoodActorsList[i].speed * pDriftWoodActorsList[i].direction)
                  end repeat
                end

                 

                ---------------------------------------- CODE --------------------------------

                1 person found this helpful
                • 5. Re: My Game Needs help UPDATE!
                  greek_dude247 Level 1

                  OK, so I got the addchild code to work. I ended up figuring it out after all of you pointed me in teh right direction. But now I need to know how to DETACH from that property I activated.

                   

                  So this is how I did it.

                  --property

                  pDrift = gWorld.model("Platform01")

                   

                  --movement

                    if (_key.keypressed("w")) then
                      if (checkForward()) then
                        pObject.translate(0,BodyVel,0)
                        if (checkDown()) then

                          end if
                        end if
                      end if

                   

                  --detector

                  on checkDown
                    col = gWorld.modelsUnderRay(pObject.worldPosition, -pObject.transform.yAxis, 2, #detailed)
                  end if
                  end

                   

                  --condition

                    if pDistanceToDrift < 20 then
                      pDrift.addChild(pObject, #preserveWorld)
                    end if

                   

                  So that's how I did it in a nutshell.

                   

                  So I read about the VOID function. How would I VOID this. I was thinking

                   

                    if (_key.keypressed("w")) then
                      if (checkForward()) then
                        pObject.translate(0,tankVel,0) -- Moves our tank forword
                        if (checkDown()) then
                          if (Detach()) then
                          end if
                        end if
                      end if
                    end if

                   

                  and then something like

                   

                  on Detach VOID = pDrift.addChild(pObject, #preserveWorld)

                  end if

                   

                  Is there a way that could work?

                  • 6. Re: My Game Needs help UPDATE!
                    DAVID NAJAR Level 1

                    Hi,

                     

                    To detach: gWorld.group("World").addChild(pObject, #preserveWorld)

                     

                    The "World" group is a default group and it is the default root for all nodes (models, lights and groups). The "World" group is present by default on any W3D (shockwave3D) member, and is the top most parent level, if you want to display (render) anything in a W3D member it has to be parenting directly to the "World" group or in a sub parenting chain belonging to this group.

                     

                    I don't know why to use VOID, if you set pObject.parent = VOID then your model hides and will be "removed from World", not deleted (just not rendered and not taken into account to any calculations). To set in the World again use pObject.parent = gWorld.group("World") or gWorld.group("World").addChild(pObject)

                     

                    At last, you can't set the value of any lingo constant like VOID, VOID is constant that represents a null or undefined value, myVar = VOID would be valid, VOID = myVar not.

                     

                    Have a nice day!

                     

                    DN

                    • 7. Re: My Game Needs help UPDATE!
                      greek_dude247 Level 1

                      while gWorld.group("World").addChild(pObject, #preserveWorld) did allow me to move away from the drift wood I was still bound to it. So I would constantly be moving with the drift wood but I could just kind of distance my self away from it. Does that makes sense? I wish I could just show it to you.

                       

                      The problem is that when "body" is at the correct distance form "driftwood" it sets the addchild property in stone. I don't have a condition to cancel that property.

                       

                      Could I say, if bodydistance is > "x" form driftwoodposition dissalow addchild property?

                      • 8. Re: My Game Needs help UPDATE!
                        DAVID NAJAR Level 1

                        Hi,

                         

                        I think you don't have to evaluate the distance factor to parenting or not, just the model below to the next player step position. Check the test I wrote for you, it works fine. Maybe you get the answers you are looking for.

                         

                        Make a new Director movie and follow the easy steps I've written  to view the example.

                         

                        Is hard to me help you without an overall clue about your code implementation, if you post or send me your movie (.dir file) maybe I can give you more exact answers.

                         

                         

                        Have a nice day!

                         

                         

                        DN