Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function main()
- lastVelocity = nil
- firstTick = true
- end
- function onTick()
- local shipVelocityNumberX = 0 -- Using variables to be more efficient
- local lastVelocityNumberX = 0
- local shipVelocityNumberY = 0 -- Using variables to be more efficient
- local lastVelocityNumberY = 0
- bf:findAllObjects(items, ObjType.Ship)
- local players = bf:getGameInfo():getPlayers();
- for i,player in ipairs(players) do
- local ship = player:getShip();
- end
- if(firstTick==true) then
- firstTick = false -- Set the variable to false, like that the if will not run again
- lastVelocity = ship:getVel() -- Put the ship's velocity in the variable
- return -- Get out of the function, so nothing else of that function is ran this time
- end
- shipVelocityNumberX = ship:getVel().x
- lastVelocityNumberX = lastVelocity.x
- shipVelocityNumberY = ship:getVel().y
- lastVelocityNumberY = lastVelocity.y
- xVelocityDifference = shipVelocityNumberX - lastVelocityNumberX
- yVelocityDifference = shipVelocityNumberY - lastVelocityNumberY
- slowNextVelocityX = shipVelocityNumberX + .8*(xVelocityDifference)
- slowNextVelocityY = shipVelocityNumberY + .8*(yVelocityDifference)
- fastNextVelocityX = shipVelocityNumberX + .5*(xVelocityDifference)
- fastNextVelocityY = shipVelocityNumberY + .5*(yVelocityDifference)
- if(shipVelocityNumberX<lastVelocityNumberX) and (shipVelocityNumberY<lastVelocityNumberY) then
- ship:setVel(point.new(slowNextVelocityX, slowNextVelocityY))
- end
- lastVelocity = ship:getVel()
- end
Advertisement
Add Comment
Please, Sign In to add comment