Problem with A.I.

Ok, I need my enemy character to walk towards me and attack, but walk away when I start attacking. I used dLoc for him to move toward’s me, but the problem is he won’t stop. He just keeps moving forward. What can I do to fix this problem?

Here’s a screen of what I’m talking about:

The enemy just keeps walking towards me even if I attack.

Well, AI is pretty broad even for this.

I’m not sure whether you’re just using logic bricks or python. If you’re using logic bricks you shouldn’t have this problem. But if you’re using python this is what you have to add…


import GameLogic as g
c = g.getCurrentController()

space = c.getSensor("space")
motion = c.getActuator("Motion")

if space.isPositive():

If you try that example in blender, if you didn’t have the else statement and pressed the space bar, the object would keep going. With the else statement applied it turns the actuator off, so it’ll stop moving and behave properly.

If you need more specific help, :wink: you’d have to elaborate more on your AI.

Jason Lin

goldentaiji, Shn275’s obviously new to Blender, and you’re throwing python at him?

Shn275, the behavior you describe can be done with logic bricks, but it’s a little too complicated to describe easily. The best I can do is point you to some documentation and suggest you check out properties, property sensors and actuators, and message sensors and actuators.

gamekit reference <- probably newest reference
game blender doc <- old but still useful