After several weekends I give up, and need some advice for next weekend.
I want that a player can walk around a rectangle if he is clicking above/below/right/left so the player would walk around it automaticly (if needed).
I have several functions like willCollide(x,y)
The world only have rectangles at the moment AABB (and I have polygon data).
The basic collision system is working good enough.
I did try to solve this without Astar but that din't go well, so before going to bed I though let's try AStar.
https://github.com/wesleywerner/lua-star
I did modify it a little so it can handle my Player: positionIsOpenFunc [self] (self.map)
Code: Select all
function Player:positionIsOpenFunc(x, y)
return self.map[x][y]
end
function Player:createMap(targetX, targetY)
local width = 2048 -- this is going to be bigger
local height = 768
-- the default map everything is walkable
self.map = {}
for x = 1, width do
self.map[x] = {}
for y = 1, height do
self.map[x][y] = true
end
end
for _, set in pairs(self.framesetsToCheckCollision) do
local frame = set:getCurrentFrame()
for y = frame.quad.h, frame.y do
for x = frame.x, frame.quad.w do
self.map[x][y] = false
end
end
end
local currentX = self.activeFrameset:getX()
local currentY = self.activeFrameset:getY()
print("check")
-- ^^^^^^^^^^ everything is fast above this line
-- local path =
-- Astar:find(
-- width,
-- height,
-- {x = math.floor(currentX), y = math.floor(currentY)},
-- {x = math.floor(targetX), y = math.floor(targetY)},
-- self,
-- false
-- )
-- if path then
-- print("yes")
---- for _, p in ipairs(path) do
---- print(p.x, p.y)
---- end
-- end
end
- Do I need astar to walk around rectangles ?
- Can astar handle bigger maps ?
- Is this the correct way to use astar ?
Thanks for the info