1 Reply Latest reply on Oct 9, 2010 4:54 PM by multiduck

    follow model


      I'm working on a car game.The car is moving around a city and the player have to collect some items.

      I want to have 2 other cars to chase my car,like a 3d pacman game where the bad gyus chase the pacman.


      here's my code for the follow behavior


      on followMe


        posMycar = mycar.transform.position -- mycar position
        posBad = van.transform.position -- the bad car position
        dista = posA.distanceto(posB) -- distance from cars




        van.transform.rotation = van.transform.rotation + vector(0,180,0)
        if(dist > 25) then -- move when distance > 25
        end if




      I run the game and the van rotates itself 90 degrees and moving to a specific direction,doesn't come to my car.

      Need help!!!!


      thank u!!!

        • 1. Re: follow model
          multiduck Level 1

          Here's a few sugestions I can make without test running your code.


          Try using worldposition or getWorldTransform() instead of a transform position, to quote the help:

          The transform property of a node is calculated relative to the 
          transform of the node’s parent, and is therefore parent-relative


          So if you cars aren't both grouped under the same parent you'r probably going to have some strange results.


            posMycar = mycar.worldPosition -- mycar position
            posBad    = van.worldPosition -- the bad car position

            dista         = posMycar.distanceto(posBad) -- distance from cars



          Also take a look at pointAtOrientation to define the models up and front direction for pointAt (with the vectorUp paramater) instead of rotating your model as with the transform position the rotation i relative it node parent and might not behave as you intend depending on  if the parent is being rotated, scaled or moved. With the rotate  command you can specify if the rotation is relative it self, parent or world, just be careful rotating around the y axis as director uses matrix calculations instead of quaternion's and


          A useful tool for debugging is 3dpi (

          http://www.3dpi-director.com/) to keep an eye on your values while running your game, it's an essential tool to use while working with 3d in director.