Ai speed movement mechanic with bricks but how with python for a more flexible result?

Hi,

So as already known the bricks in python for the game engine, can’t create the best effect as raw python code can.

So this basic example, I have setup, a cube moves to the target, but can only go at the speed setup by a brick, as with the code, you can add variables, so it moves at a certain time, and speed in order to create a realistic AI - player interaction.

In one of my small mini game projects this is exactly what is going on, how ever when I think about it, is it the AI that is too big or small, that gets wiped out by the player’s bullet, or is the scene too small for that type of interaction and the speed of some using the steering brick. Since there is also no control of the bullet firing object. That requires animation and a cursor point/cross hairs.

Is the brick setup pretty much at its limit as my basic example shows. I used 2.76 here

aispeedbricktheory.blend (411.0 KB)

So what python code would I be needing to create a speed increase or slow down with an Ai to begin with.

I could try some basic python language lessons on youtube, but I don’t think I can really do much.

What example code could somebody type up for the AI bricks there.

Thank you.

Hi - use that steering.velocity = 0.100 or use float property - own['speed] and insert in steering, steering.velocity = own[‘speed’], if you use property you always control and assign speed for movement unit. I hope you understand how connect actuator steering in python controller brick for use python scripts - because set speed for steering only logic brick impossibly

Hmm, i will need an example. Create a property? on the AI, and then a script is needed using the python script brick?

So the bricks on their own can’t be used to create a dynamic, Ai movement, moving to collide with the player is what I understand from your response.

In one of my old release files, the AI pretty much to what is there, but in my newer wip file that didn’t get anywhere because was about both parties in motion, it needed to be so that the AI wouldn’t get wiped out all in one, so that there wasn’t a challenge to the player getting damaged. But because the player didn’t have animated targeting movement, it wasn’t easy to do so. :neutral_face:

Yes, you need a script for managing the unit Logical blocks and Actuators will be sensors and execution blocks they can be obtained in the script. The problem with using the steering drive is different - it cannot bypass three objects standing in a pile or in a row that have the property of obstacles because it falls into the local minimum to solve the local minimum problem, you need to use a beam obstacle avoidance system if the unit is stuck and cannot find the right solution. If you need a script that will start the steering drive actuator here it is -
def start(cont):
from bge import logic
scene = bge.logic.getCurrentScene()
own = cont.owner
speed = own[‘speed’]
steering = cont.actuators[‘Steering’]
if not ‘start’ in own:
steering.target = scene.objects[‘Target’] # assign target you can assign goals that are located on the layer in which the unit is located
steering.distance = 1.000 # assign distance off steering you can set the distance to turn off the actuator depends on the distance to the target
steering.velocity = own[‘speed’] # assign speed
steering.navmesh = scene.objects[‘Navmesh’] # assign navigation mesh you can assign a navigation mesh-even if it is loaded via bge. logic. LibLoad()

     cont.activate(steering) # start use steering
     cont.deactivate(steering)# stop use steering

Can I apply this to the AI in my example file? So open a text file, then save it, and then add a python script brick, and remove the steering brick?

def start(cont):
from bge import logic
scene = bge.logic.getCurrentScene()
own = cont.owner
speed = own[‘speed’]
steering = cont.actuators[‘Steering’]
if not ‘start’ in own:
steering.target = scene.objects[‘Target’] # assign target you can assign goals that are located on the layer in which the unit is located
steering.distance = 1.000 # assign distance off steering you can set the distance to turn off the actuator depends on the distance to the target
steering.velocity = own[‘speed’] # assign speed
steering.navmesh = scene.objects[‘Navmesh’] # assign navigation mesh you can assign a navigation mesh-even if it is loaded via bge. logic. LibLoad()

You can use this text as a starting script i use something similar and all work, you will need to indent (tab) in text - after the colons there are two spaces, note that if the condition is shifted and a colon follows it, then four spaces are already considered from the edge, create a sensor that will set the start of the script execution - keyboard key or delay for start, and you need a controller block with a script and a Steering actuator, need create property float “speed”, in scene need objects - navmesh with the name Navmesh and target with the name Target

I’ve got something going here, point out where I’m not done yet.

For this example there is no nav mesh, in the actual file I did create a couple of years ago, there is a navmesh.

SimplePathfinding_Steering.blend (552.0 KB)
Hi i create simple example for pathfinding and use actuator steering - use UPBGE version 0.2.5, i make navmesh, unit and target, if you click right mouse button in ground you start unit and assign target - script is very simple, i hope this example help for you

The problem is my file is from blender game engine, not the use of upbge, the recent file I was trying to get up and running that needed code, spider smith battle works in upbge.

So my example I have made in the game engine, would need to work for a file that works in that engine, not upbge. If this was for the recent file I may of considered trying to do that upbge. I’m not a programmer, at the end of the day. So the file I am focusing on won’t work for upbge.

I did open the file in blender 2.76, it runs, but what is suppose to happen? There is no movement.

Just click mouse right button in ground - this start logic simple pathfinding

I tried that, nothing appears to work. I am using 2.76 blender 3d. So if you made this file in upbge,it could be the reason. Some files may not work when done in upbge and then load into blender 3d. The spider smith file works in blender game engine and upbge. The only one.

I would need any python program for blender game engine since the file was made in it.

The file does work, in upbge only. My wip file is in this clip, so you get the task I’m trying to get working. The AI is following the player, so in order for there to be a bit of an equal challenge, python code is the only real alternative than the bricks, isn’t bad, but for example, an ai at the very back can’t accelerate once the AI has been wiped out.

UPBGE is not entirely backwards compatible with BGE… Logic-Bricks migrations tend to also break the process too.

Just translate logic bricks, script, and objects in BGE frome UPBGE blend file, not use copy insert and not use append objects, create new file in bge and reconstruction my example and append text script for drive unit

Hmm, the file example doesn’t quite make out what the file I have in the video is doing. So the purpose of a python code script is to be able to control the speed, so once some AI are taken out or removed from the scene, the next AI need to be able to accelerate ahead to attack the player.

As my example file at the top of the topic shows the file example as shown in the video.

If the front AI is 1,000, then the back AI need to be 2,500 or something. As is, it doesn’t quite work for it to be a challenge. At least not a difficult one.

https://blenderartists.org/uploads/default/original/4X/d/7/5/d75045afc150fd0d24ff60bca0727b63d042f50e.jpeg

If you use python and steering actuator in units for pathfinding or finding and tracking to player you always assign or change speed in actuator steering - you need get actuator steering = cont.actuators[‘Steering’] and assign new speed - steering.speed = 5.000, I’m only telling you how to contact the actuator, but the conditions under which the speed change occurs and something else you should write yourself to check the line of sight use ray = own.RayCast (end, start, 0,") where the end and start variables are from where and where the beam is thrown hit = ray[0] will get an object and you can check its properties to change something in the steering actuator

I was thinking about the program, and using the bricks to may be pull this off. I think I can, by using a property, once one AI has been edited or removed, the property would switch on to then make another AI further back accelerate with a new steering brick. It could work…

Then you will need several steering drive actuators with different speeds - but the problem is that they will be configured for only one purpose and will have one navesh, yes, they can be switched back and forth and it will work but such a system will not be very flexible

I was thinking that.

I tried editing the file I uploaded here, so a property on the AI cube, and then collision with the target cube, so it should remove, and then the next steering brick targeting the back AI cube would then move forward much quicker than the first, in order to keep up at the challenge to the player object.

Property float for the cube.001 and then I called it target for property, once collision with target cube, ai1 would remove, but that doesn’t happen. I also added a navmesh, not really that important for this, since it is about programming the AI speed movement.

Declaring a variable of integer or boolean doesn’t change that, float is typically the default in the game engine.