Hi 1sk8kr3w
I can't run your code you've posted as I don't have the AI plug in.
However, I have noticed this line:
c= abs((PposX#-ZposX#)^2)+abs((PposZ#-ZposZ#)^2)
You don't need the ABS command here as any number that is squared will always be positive.
(10-3)^2 = (+7)^2 = 49
(3-10)^2 = (-7)^2 = 49
I also think that you should be calculating the value "distance#" after the zombie has moved but before this bit:
if AI Get Entity Can Fire(x) = 1 and distance#<=100
Zdoing = 1
ZombieAttack(x)
endif
I would move the zombie, calculate the distance then make the decision to attack, which is dependant on distance. Thinking about it, what you have is the zombie making the decision to attack based on the distance# the last zombie was from the player (i.e. zombie 3 is making its decision based on how far zombie 2 is from the player).
To stop the zombies going through each other you need to determine if the zombie is or has moved into another zombie. If it does/has then do something to stop the zombie going through the one it's walked into (i.e. put it back to its old position, turn it into a bat and have it fly away, have it move to the side, kill the other zombie or whatever).
As I said, I can't run your code so I can't see how the zombies are moving around. I took out all the AI stuff and replaced the media with primatives and got a third person camera view when I ran it. Based on this, I've come up with a demo of how I would start a game like this, without all the media, plug ins and what not, just primatives and native DBP code.
sync on
sync rate 60
set window off
hide mouse
`use a matrix to give sometime to gauge relative speeds and position to the world coordinates
make matrix 1, 1000, 1000, 10, 10
`make a green box for the player
make object box 1, 20,50,20
color object 1, rgb(0,255,0)
position object 1, 500,25,500
`make ten boxes for the zombies
for i = 2 to 11
make object box i, 20,50,20
position object i, rnd(1000),25,rnd(1000)
next i
`set a variable for the facing of the player
player_facing# = 0.0
`main game loop
do
`wasd movement
if keystate(17) = 1 then move object 1, 5
if keystate(31) = 1 then move object 1, -5
if keystate(30) = 1 then move object left 1, 5
if keystate(32) = 1 then move object right 1, 5
`mouse look (i.e. turning)
player_facing# = wrapvalue(player_facing# + mousemovex()*0.5)
`rotate the player
yrotate object 1, player_facing#
`zombie controls
for i = 2 to 11
old_zombie_x# = object position x(i)
old_zombie_y# = object position y(i)
old_zombie_z# = object position z(i)
`point the zombie at the player
point object i, object position x(1), object position y(1), object position z(1)
`move the zombie toward the player
move object i, 2
`stop zombies walking through each other
for j = 2 to 11
if j <> i
if object collision(i,j) = 1
`if the zombie has walked into another zombie
`position zombie at old coordinates
`this makes it look as it hasn't moved
position object i, old_zombie_x#, old_zombie_y#, old_zombie_z#
endif
endif
next j
`calculate the distance between the player and the zombie
distance# = sqrt((object position x(1)-object position x(i))^2 + (object position z(1)-object position z(i))^2)
`if zombie is close to the player
if distance# < 200
`if the zombie is close, turn it red
color object i, rgb(250,250,0)
else
`if the zombie is further away, turn it yellow
color object i, rgb(250,0,0)
endif
next i
`set the camera to follow the player
set camera to follow object position x(1), object position y(1), object position z(1), player_facing#, 100, 75, 5, 0
set cursor 0,0
print "wasd and mouse to move"
sync
loop
The best tactic so you can see what the zombies are doing is to move backward and strafe either left or right.
Quote: "There aren't many guides for intermediate DBP users"
It's time to make the transition from beginner to intermediate and start figuring things out for yourself. Example's and tutorials will only take you so far, they're mainly to show you what is possible as opposed to telling you everything that you might want to do. What you need to do, and I'm not intending to offend, is to learn how to solve problems. That's the real difference between a beginner and an expert
I hope my demo gives you some ideas.