Guest User

Untitled

a guest
Mar 26th, 2014
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.57 KB | None | 0 0
  1. function main()
  2. lastVelocity = nil
  3. firstTick = true
  4.  
  5. end
  6.  
  7. function onTick()
  8. local shipVelocityNumberX = 0 -- Using variables to be more efficient
  9. local lastVelocityNumberX = 0
  10. local shipVelocityNumberY = 0 -- Using variables to be more efficient
  11. local lastVelocityNumberY = 0
  12.  
  13. bf:findAllObjects(items, ObjType.Ship)
  14. local players = bf:getGameInfo():getPlayers();
  15. for i,player in ipairs(players) do
  16. local ship = player:getShip();
  17. end
  18.  
  19. if(firstTick==true) then
  20. firstTick = false -- Set the variable to false, like that the if will not run again
  21. lastVelocity = ship:getVel() -- Put the ship's velocity in the variable
  22. return -- Get out of the function, so nothing else of that function is ran this time
  23. end
  24.  
  25. shipVelocityNumberX = ship:getVel().x
  26. lastVelocityNumberX = lastVelocity.x
  27. shipVelocityNumberY = ship:getVel().y
  28. lastVelocityNumberY = lastVelocity.y
  29. xVelocityDifference = shipVelocityNumberX - lastVelocityNumberX
  30. yVelocityDifference = shipVelocityNumberY - lastVelocityNumberY
  31. slowNextVelocityX = shipVelocityNumberX + .8*(xVelocityDifference)
  32. slowNextVelocityY = shipVelocityNumberY + .8*(yVelocityDifference)
  33. fastNextVelocityX = shipVelocityNumberX + .5*(xVelocityDifference)
  34. fastNextVelocityY = shipVelocityNumberY + .5*(yVelocityDifference)
  35.  
  36. if(shipVelocityNumberX<lastVelocityNumberX) and (shipVelocityNumberY<lastVelocityNumberY) then
  37. ship:setVel(point.new(slowNextVelocityX, slowNextVelocityY))
  38.  
  39. end
  40.  
  41.  
  42. lastVelocity = ship:getVel()
  43. end
Advertisement
Add Comment
Please, Sign In to add comment