[alpha v8]Wastelands Of Death
Posted: Thu Dec 13, 2012 6:20 pm
moved thread!
Code: Select all
dx = player.x - zombie.x
dy = player.y - zombie.x
Code: Select all
length = math.sqrt(dx*dx+dy*dy)
dx = dx/length
dy = dy/length
Code: Select all
zombie.x=zombie.speed*dx*dt
zombie.y=zombie.speed*dy*dt
micha wrote:Nice and already quiet well playable.
The enemy movement is not very well. you should change it, so zombies don't cluster so much.
First, take the distance vector from a zombie to the player:Then divide this vector by it's lengthCode: Select all
dx = player.x - zombie.x dy = player.y - zombie.x
Then move the zombie in this direction, multiplied with it's speedCode: Select all
length = math.sqrt(dx*dx+dy*dy) dx = dx/length dy = dy/length
Now the zombies should walk to the player in straight lines.Code: Select all
zombie.x=zombie.speed*dx*dt zombie.y=zombie.speed*dy*dt
and nearly forgot about it: print("micha has a nice avatar!")micha wrote:Nice and already quiet well playable.
The enemy movement is not very well. you should change it, so zombies don't cluster so much.
First, take the distance vector from a zombie to the player:Then divide this vector by it's lengthCode: Select all
dx = player.x - zombie.x dy = player.y - zombie.x
Then move the zombie in this direction, multiplied with it's speedCode: Select all
length = math.sqrt(dx*dx+dy*dy) dx = dx/length dy = dy/length
Now the zombies should walk to the player in straight lines.Code: Select all
zombie.x=zombie.speed*dx*dt zombie.y=zombie.speed*dy*dt
micha wrote:Nice and already quiet well playable.
The enemy movement is not very well. you should change it, so zombies don't cluster so much.
First, take the distance vector from a zombie to the player:Then divide this vector by it's lengthCode: Select all
dx = player.x - zombie.x dy = player.y - zombie.x
Then move the zombie in this direction, multiplied with it's speedCode: Select all
length = math.sqrt(dx*dx+dy*dy) dx = dx/length dy = dy/length
Now the zombies should walk to the player in straight lines.Code: Select all
zombie.x=zombie.speed*dx*dt zombie.y=zombie.speed*dy*dt
Code: Select all
function zombie_move(dt)
for i,c in ipairs(zombies) do
if c.dead == false then
dx = player.x - c.x
dy = player.y - c.y
length = math.sqrt(dx*dx+dy*dy)
dx = dx/length
dy = dy/length
c.x=zombies.speed*dx*dt
c.y=zombies.speed*dy*dt
end
end
end
jjmafiae wrote:i have a problem i cant get it to work
Code: Select all
function zombie_move(dt)
for i,c in ipairs(zombies) do
if c.dead == false then
local dx = player.x - c.x
local dy = player.y - c.y
local length = math.sqrt(dx*dx+dy*dy)
dx = dx/length
dy = dy/length
c.x= c.x + zombies.speed*dx*dt
c.y=c.y + zombies.speed*dy*dt
end
end
end
Can you specify what exactly not works?jjmafiae wrote:i have a problem i cant get it to work:
Code: Select all
function zombie_move(dt) for i,c in ipairs(zombies) do if c.dead == false then dx = player.x - c.x dy = player.y - c.y length = math.sqrt(dx*dx+dy*dy) dx = dx/length dy = dy/length c.x=zombies.speed*dx*dt c.y=zombies.speed*dy*dt end end end
the zombie don't move it just stands still!micha wrote:Can you specify what exactly not works?jjmafiae wrote:i have a problem i cant get it to work:
Code: Select all
function zombie_move(dt) for i,c in ipairs(zombies) do if c.dead == false then dx = player.x - c.x dy = player.y - c.y length = math.sqrt(dx*dx+dy*dy) dx = dx/length dy = dy/length c.x=zombies.speed*dx*dt c.y=zombies.speed*dy*dt end end end
I have a wild guess: your variable "zombies" is a table of entities which have the information on all zombies. In the last lines you use zombies.speed. Maybe you mean c.speed? Or to test it you can also just use a global variable speed and set it to any value.
THANKS ROBIN AND MICHA YOU HAVE BEEN A HUGE HELP (i will put you in special thanks section when the game is ready!)Robin wrote:jjmafiae wrote:i have a problem i cant get it to workThe "local" declarations are not necessary, but they are proper.Code: Select all
function zombie_move(dt) for i,c in ipairs(zombies) do if c.dead == false then local dx = player.x - c.x local dy = player.y - c.y local length = math.sqrt(dx*dx+dy*dy) dx = dx/length dy = dy/length c.x= c.x + zombies.speed*dx*dt c.y=c.y + zombies.speed*dy*dt end end end