It looks like you're new here. If you want to get involved, click one of these buttons!
function GameScene:moveToPlayer(pursuer) pursuer.pursuitState = "following" if pursuer.path ~= nil then for i = 1, table.getn(pursuer.path) do local newX = pursuer.path[i].x -1-- Secret Sauce. Shh! local newY = pursuer.path[i].y -1 local goalX, goalY = newX * boardRectSize , newY * boardRectSize -- local actualX, actualY, cols, len = world:move(pursuer, goalX, goalY) local mc1 = MovieClip.new{ {1, 100, b, {x = {pursuer:getX(), goalX, "linear"}, y = {pursuer:getY(), goalY, "linear"}}} } print("I want to move to "..goalX..", "..goalY..". My actuals are "..actualX..", "..actualY) --pursuer:setPosition(actualX , actualY) --[[ -- prints "Collision with A" for i=1,len do -- If more than one simultaneous collision, they are sorted out by proximity local col = cols[i] print("Collision with "..col.other.name) end ]]-- end end end |
Comments
Yes it's happened because you're the same local object "mc1" in your "for loop" so you get strange results 'cos refresh the same local object in each loop.
So first you can defined local variable mc1={} outside of you "for loop" and after you can put the next (I haven't had test it yet):
[-] Liasoft
When I move my player, I move his bitmap and bump.lua body by 1 pixel in the same function on every frame. This is a combination of bump's world:move() and setPosition().
I figured if I wanted to do the same with the enemies, I would need to get a line between each valid path point (i in pursuer.path), and get every co-ordinate along that line. I could then have a nested loop inside my path points loop. Which sounds a bit hairy to be honest.
I think the thing I was missing was velocity! (and also of course, fixing my dodgy vars)
Thanks! I will try implementing this tonight when I get home.
I can see this because the getX() on the start of every loop teleports the enemy back slightly to a previous point in the path.
And also the path becomes warped as the enemy proceeds, almost as if he starts taking a shortcut because the goalX and goalY have changed mid tween...
1. Do your monsters only move in four directions, ie left, right, up, down?
2. Do you want your monsters to move at the same speed when moving from point to point?
edit: nevermind I got curious and made an example 8-} 8-} 8-}
Likes: Astirian
I absolutely recommend http://www.gameaipro.com/ with regards to this kind of thing as well. The first book (it's FREE) contains a very good section on state based agents, which this example uses. It is totally worth a read, and the earlier section on random numbers is fascinating
Likes: Astirian, HubertRonald, pie
I need to stop trying to do everything in the scene and start making proper classes for things, I'm being a bit too procedural I think.
Lots of homework to do, that book you mentioned looks fantastic! I'll definitely give it a read. On a side note I recently picked up Level Up by Scott Rogers, once I've got the basics down and a few more light games out the door I'm planning to start coming up with my own gameplay concepts.
You should definitely be creating small reusable classes. Having lots of classes makes it a lot easier to prototype possible new games. I mashed together a basic platformer in a day and a half recently and that would not have been possible if I didn't have all those little classes just waiting to be combined into something new.
The Game AI Pro book is pretty big (there are like three books now) but you only need to read sections as required or when you feel like reading something technical
I might grab that other book by Scott Rogers if the price ever drops ~:>
Likes: Astirian
Edit: Sorted it, I was calling setPath() on every update, d'oh!
Likes: antix
Likes: antix
[-] Liasoft