This site requires JavaScript, please enable it in your browser!
Greenfoot back
m.legere1323
m.legere1323 wrote ...

2011/3/4

AI Stuff Again...

m.legere1323 m.legere1323

2011/3/4

#
So I'm tying to make AI for a Tron light cycle themed game so that when the cpu sees another light path (a 5x5 px actor) it turns left or right depending on the situation...I've tried using turn() and getObjectAtOffset() but I can't seem to find a way that works consistently, and the cpu keeps running into itself also, even though I thought I'd told it not to...maybe my understanding of the use of getObjectAtOffset() is wrong? Anyone have any insight?
m.legere1323 m.legere1323

2011/3/4

#
***** getOneObjectAtOffset() *****
davmac davmac

2011/3/5

#
What offset are you specifying?
m.legere1323 m.legere1323

2011/3/5

#
Well Im looking to see if there's and object in front of the cpu, and I want it to turn a certain way based on whats also on the left or right side of itself....for example, if there's more objects of the left side and theres something in front..then go right etc...
m.legere1323 m.legere1323

2011/3/5

#
however, im not sure how to approach and translate this into real code
mik mik

2011/3/5

#
Well, "in front" would depend on the direction it is facing. In general it is like this: getObjectAtOffset(10, 0, null) would check for objects 10 cells to the right of the current actor. This is measured from the cell the actor is in, which it at the centre point of the actors image. In other words: if you have 1 pixel cells, then this call would check the location 10 pixels from the centre of the actor. This might be what you want if you are facing right. You would have to translate this for facing other directions. For example getObjectAtOffset(0, 30, null) checks 30 cells below the actor. You also have to consider your actor's speed. If the actors are fast moving, and the walls are thin, you might miss it. Say, one step you check and you don't see a wall (because you're not close to the wall yet), and you move 20 cells forward, then if your wall is only 10 cells wide, you may not see it in the next step because you have already moved past it. In that case, you either need thicker walls, slower speed, or you need to check multiple points in front of you.
m.legere1323 m.legere1323

2011/3/5

#
That's exactly what I needed, thanks! I'm working on multiple scenarios right now, and I really appreciate all the help!
You need to login to post a reply.