ID:160282
 
Basically I was sort of hoping that if the NPC couldn't reach the player through step_to, it would get as close to the user as possible and keep trying to 'Bump()' whatever was in it's way. I have a dense object in which bumped enough breaks, however the step_to has this great idea to not bump in to anything ever. How would I go about making it so if there was no way to get through to the user, it would begin 'Bump()ing' up to the closest thing to the user! Thanks.

EDIT: However just to clarify, I still want my ai smart enough to not get stuck behind walls and always try to find a path to the user! :p

|
| My current AI code.
V


mob
var
target
delaytime=3 //minimum
proc
ai()
for()
sleep(src.delaytime)
var/templist[]=new
for(var/mob/m in world)
sleep()
if(m.playing)
templist+=m
var/playersfound
for(var/a in templist)
playersfound=1
if(!playersfound) //no targets found.
return
src.target=pick(templist)
var/mob/n=src.target
while(n.playing)
sleep(src.delaytime)
if(get_dist(n,src)<2)
step_towards(src,src.target)
else
step_to(src,src.target) //HERE.
src.target=n
step_to() still bumps into objects if it's stuck in a nook, or something, I think. Either way, step_towards doesn't take objects into account, so you could probably use that. Or you could use step(get_step_to(movable atom,atom)); get_step_to() always returns a turf, and step() always moves something.
In response to Jeff8500
Jeff8500 wrote:
step_to() still bumps into objects if it's stuck in a nook, or something, I think.

It doesn't actually, and that's what the problem is. :p


step(get_step_to(movable atom,atom))

What would I input as a second argument?

I tried this, but it didn't work: step(src,get_step_to(src,src.target))
In response to Speedro
I can't see how to get it to work, even after battling with it for several hours. I guess I'll just make the the object non-dense and whenever a mob attempts to Enter() it, I'll return null and give it the same effect. (Not very preferable though) Is this a better way?
In response to Speedro
Woops. step() uses a direction, not a turf; use Move() instead!

movable atom.Move(get_step_to(src,target atom),get_dir(src,target atom))
In response to Jeff8500
Nope! Still doesn't work. Does it have something to do with the object I'm using that breaks being a object? :s
In response to Speedro
Yes, it seems the Move function works the exact same as the step_to function normally does, unfortunately. They still aren't trying to Bump() into the closest thing to the player if there's no clear path to them. :/
In response to Speedro
In my game, they only Bump() objects when trapped by two:

[]
Me []En
[]

Do you want them to Bump() objects more frequently than that? If so, you might need to use your own stepping algorithm that would work better than step_towards(), but worse than step_to().