Forum

> > CS2D > Scripts > smouth Following bot
Forums overviewCS2D overview Scripts overviewLog in to reply

English smouth Following bot

4 replies
To the start Previous 1 Next To the start

moved smouth Following bot

QKDJHSKUYPOIELJKHQSKDYIUQ
User Off Offline

Quote
hello,
I request your help : I am writing a AI script, this is the part of the script which handle the follow behaviour of bots and I am having a problem.
the code bellow is working well when the player who host the server is walking but bad when it's someone else, for them bots are "jumping". someone can explain me why it react like that ?
do you guys have ideas to fix that? - have a smouth following bot
here the behaviour with the host:
IMG:https://i.postimg.cc/xjmSxTMx/recording.gif

here the behaviour with someone else (ping 20-40):
IMG:https://i.postimg.cc/QNQyKBp3/recording-1.gif

here the code : (vai_son[id] is the id of the bot)
1
2
3
4
5
6
7
8
9
10
addhook("move","_move")
function _move(id,x,y,walk)
	if(not player(id,"bot"))then
		msg("player_x : "..player(id,"tilex"))
		msg("player_y : "..player(id,"tiley"))
		msg("bot_x : "..player(vai_son[id],"tilex"))
		msg("bot_y : "..player(vai_son[id],"tiley"))	
		ai_goto(vai_son[id],player(id,"tilex"),player(id,"tiley"),walk)
	end
end
any help is welcome, thanks.
edited 1×, last 21.11.20 12:56:41 pm

old Re: smouth Following bot

Pagyra
User Off Offline

Quote
msg command same as ai_goto have some delay, so try remove msg code part (or just move it to another function) and use correct players coordinates, or add ping check to add table with waypoints between old and new player coordinates, in same way you can have player aim angles, shoot positions and so on
edited 3×, last 23.11.20 07:21:05 am

old Re: smouth Following bot

VADemon
User Off Offline

Quote
1) ai_goto works with tiles, you call it on cs2d lua hook move that's for pixels. cs2d lua hook movetile must give instant improvement

2) Otherwise what @user SQ: said. Interpolation/Extrapolation, reduce frequency at which you call ai_goto; try to use cs2d lua cmd ai_move

First post in 10 years? I have bad news for @user DC.

old Re: smouth Following bot

QKDJHSKUYPOIELJKHQSKDYIUQ
User Off Offline

Quote
thanks you @user SQ: @user Pagyra: @user VADemon: for taking time to answer.

I tested the 1st solution from @user VADemon: which seems to work on paper but it doesn't in reallity.. I found the probable reason on the commentary space of the ai_goto command :

Quote
"Note that this command has to be called EVERY frame (in always hook for example)."

@user DC: can you confirm ?

with this adjustement the code is working better with 20ping now (since ai_update_living is called each frame):
1
2
3
function ai_update_living(id)
ai_goto(id,player(vai_father[id],"tilex"),player(vai_father[id],"tiley"))
end
I will test the behaviour with bigger ping...interpolation may be in that case the only solution.. but because ai_goto have to be called everyframe doing arymethic operation may lead to performance problems no?

@user DC: does ai_move need to be called everytime also ?

EDIT : @user DC: ai_update_living is called each frame (60) or same as always hook (~50/sec)?

good night
edited 2×, last 23.11.20 08:21:28 pm
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview