Author Topic: Making Bots Avoid Light?  (Read 741 times)

I was wondering if it was possible to make a certain kind of bot avoid light. For example, if the bot was chasing a player, and the player turned on their light, the bot would stay at a distance from the player, though still following. If the player turns off their light, the bot would continue attacking and pursuing normally.

So, is this possible? Can someone make a script to be included with the bot playertype?

You could make it so when you turned on your light, the AIAvoid variable thing ( I don't know what it's called) is turned to 1, and when your light is off, it is set to 0. But I don't know if you make them follow you through this. It might take some AI coding, I don't really know how to do that.

Zombie? and if that is true you would need flash light battery's or someone would just leave there light on

If you're making the bot from scratch, this should be easy to do. Just see if the light is mounted to the player, if it is then using some vector math it's pretty easy.
Code: [Select]
%ppos = getWords(%player.getPosition(), 0, 1) SPC "0"; //get the player's position, make z = 0 because we're not interested
%bpos = getWords(%bot.getPosition(), 0, 1) SPC "0"; //get the bot's position

%vec = VectorNormalize(VectorSub(%bpos, %ppos)); //get the vector between the player and bot plus make it as small as it can be so we only have direction
%disp = VectorScale(%vec, 8); //Scale the vector 8 units so the bot will stay 8 units away, this is the displacement the bot will be at

%pos = VectorAdd(%ppos, %disp); //get the new position by adding the original and displacement
%bot.setMoveDestination(%pos); //make the bot go there


Pop that into a schedule and activate it when the player has a light, it should work but I haven't tested it.

Yeah, I would trust Nitramtj.

Lol, Vampire bot :3

im no scripter but couldn't you make it so theres a zone when your lights on that a bot can't enter

If by zone you mean a physical object, that would be annoying and unnecessary because you would have to update its position every time the player moves. Performing calculations using the player's position is more efficient.

Well, we aren't exactly scripting it from scratch. It's a zombie type. Would that code work with a zombie?

But thanks for your help anyway, Nitramtj.

If you're making the bot from scratch, this should be easy to do. Just see if the light is mounted to the player, if it is then using some vector math it's pretty easy.
Code: [Select]
%ppos = getWords(%player.getPosition(), 0, 1) SPC "0"; //get the player's position, make z = 0 because we're not interested
%bpos = getWords(%bot.getPosition(), 0, 1) SPC "0"; //get the bot's position

%vec = VectorNormalize(VectorSub(%bpos, %ppos)); //get the vector between the player and bot plus make it as small as it can be so we only have direction
%disp = VectorScale(%vec, 8); //Scale the vector 8 units so the bot will stay 8 units away, this is the displacement the bot will be at

%pos = VectorAdd(%ppos, %disp); //get the new position by adding the original and displacement
%bot.setMoveDestination(%pos); //make the bot go there


Pop that into a schedule and activate it when the player has a light, it should work but I haven't tested it.


Would it be possible to get the fxLightData's Radius variable for the vector amount of distance the bot will stay away? Or would that not really matter since almost all lights are essentially the same radius (except Bright)?

Also you could do something with brick-mounted lights, like if the player is within x radius of the brick the bots will ignore the player and move about elsewhere, also they would stay a certain radius distance away from that brick as default. This would add to the freakiness since, even if you'd find shelter in light, the bots would still be out there somewhere, in contrast to you simply killing them because they stay on the boarder picking their noses.
« Last Edit: June 15, 2009, 10:28:29 AM by Muffinmix »

This is for the Bug Mod. So one kind of bug type is attacking you, you've got no weapons, so you switch on your light. Instead of running away, they just retreat and stay at a farther distance away from you than normal. If you turn off your light, they will continue to attack/run normally.