title: Setting the linear velocity of a physics object from an external module in Corona SDK
body: <p>I am working on a classic RPG and need some help with joystick based movement.  The player should be able to move the character in any direction with a circular pad that he moves with his thumb.  This should be familiar from FPS games where a pad controls the left/right and forward/backward movement of the character.  My code for constructing the character is this:</p>
  
  <pre><code>    local player = {}
      local player_mt = { __index = player }
  
      function player.new( --[[ parameters for player instance ]]-- )
        local newPlayer = { --[[ player attributes here ]]-- }
  
        newPlayer.image = display.newImage("testImage.png")
  
        physics.addBody( newPlayer.image, "kinematic" )
  
        return setmetatable( newPlayer, player_mt )
      end
  </code></pre>
  
  <p>And this is the function for moving the character (still in the same .lua file):</p>
  
  <pre><code>    function player:startMoving( xMotion, yMotion)
        self:setLinearVelocity( xMotion*player.speedModifier, yMotion*player.speedModifier)
      end
  </code></pre>
  
  <p>Now in my main.lua file where I am testing out all of my functions, I initialize a new player, create a circle for the joystick, add a touch event listener to it, and use that to call my move function:</p>
  
  <pre><code>    local physics = require("physics")
      physics.start()
  
      local player = require("player")
  
      local myPlayer = player.new( --[[player params]]-- )
  
      myControl = display.newCircle( 300, 300, 100 )
      myControl:setFillColor( 100, 100, 100 )
      myControl:addEventListener( "touch", controlCharacter )
  
      function controlCharacter( event )
        if( event.phase == "began" ) then
          x = myControl.x
          y = myControl.y
        elseif( event.phase == "moved" ) then
          myControl.x = event.x
          myControl.y = event.y
          myPlayer:startMoving( myControl.x - event.x, myControl.y - event.y )
        elseif( event.phase == "ended" ) then
          myControl.x = x
          myControl.y = y
        end
      end
  </code></pre>
  
  <p>When I run this, I get the following error:  attempt to call method 'setLinearVelocity' (a nil value).  It's like it doesn't recognize the player as a physics object, but if I change the player physics object type in the player.lua file to dynamic,</p>
  
  <pre><code>    physics.addBody( newPlayer.image, "kinematic" )  ___
                                                          |
      physics.addBody( newPlayer.image, "dynamic" )    &lt;--
  </code></pre>
  
  <p>then the gravity function operates fine, it falls right off the screen.  Can anyone help me with what's going on here?</p>