Sign in to follow this  
zabo

Enemies not chasing player!

Recommended Posts

heres a peice of my code---------------> fanatic=loadmesh("fanatic.b3d") for a=1 to 100 fanatic2=copyentity(fanatic) positionentity fanatic2,rnd(1000,1200),0,rnd(200,400) freeentity fanatic next While not keyhit(1) if entitydistance (fanatic2,player)<1000 then pointentity fanatic2,player moveentity fanatic2,0,0,1 endif For some reason the "fanatics" wont chase me the player. can you help me find out why? [Edited by - zabo on November 22, 2007 10:30:11 PM]

Share this post


Link to post
Share on other sites
You overwrite your objects in your loop, so that you lose the previous one. You need to store your fanatics in a list to overcome this problem, if positionentity does it not.
Do not free the variables you need to use in next cycles (fanatic).
I also suggest you to declare the variables you use (or include the declarations in the code you post).

Try somethig like this (is that vb?):

Dim fanatic_list(1 to 100) as FANATIC_TYPE, fanatic2 as FANATIC_TYPE 'declare list

fanatic=loadmesh("fanatic.b3d")
for a=1 to 100
fanatic_list(a)=copyentity(fanatic)
positionentity fanatic_list(a),rnd(1000,1200),0,rnd(200,400)
next
freeentity fanatic 'free AFTER the loop

While not keyhit(1)
for a = 1 to 100 'loop over all the enemies
Set fanatic2 = fanatic_list(a)
if entitydistance (fanatic2,player)<1000 then
pointentity fanatic2,player
moveentity fanatic2,0,0,1
endif
next
loop



Another way would be let positionentity to manage the list of fanatics, and entitydistance may loop over all the fanatics and return the closest one.

Hope it helps!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this