hi i am stuck and could use a little help
what i want: zombies that follow the main character
what i have: zombies that follow the character untill a new zombie comes along. then they just drift of into the direction that they have been going in
here is my code:
[lua]local physics = require(“physics”)
physics.start()
physics.setGravity( 0, 0 )
local function dragBody( event )
local t = event.target
local phase = event.phase
if “began” == phase then
display.getCurrentStage():setFocus( t )
t.isFocus = true
– Store initial position
t.x0 = event.x - t.x
t.y0 = event.y - t.y
– Make body type temporarily “kinematic” (to avoid gravitional forces)
event.target.bodyType = “kinematic”
– Stop current motion, if any
event.target:setLinearVelocity( 0, 0 )
event.target.angularVelocity = 0
elseif t.isFocus then
if “moved” == phase then
t.x = event.x - t.x0
t.y = event.y - t.y0
elseif “ended” == phase or “cancelled” == phase then
display.getCurrentStage():setFocus( nil )
t.isFocus = false
– Switch body type back to “dynamic”, unless we’ve marked this sprite as a platform
if ( not event.target.isPlatform ) then
event.target.bodyType = “static”
end
end
end
– Stop further propagation of touch event!
return true
end
Bball = display.newImage( “Bball.png”,300,400 )
physics.addBody( Bball, { density = 1,friction=0, bounce=.5, radius= 30} )
Bball:addEventListener( “touch”, dragBody )
local dudes = {}
function enemymaker(event)
function enemymaker2(event)
ball = display.newImage( “ball.png”,math.random (0, 600),1100 )
physics.addBody( ball, { density = 2,friction=0, bounce=.1, radius= 5} )
bx=ball.x
by=ball.y
k=Bball.x-bx,2
z=Bball.y-by,2
ball:applyForce( k/100,z/100, ball.x, ball.y )
dudes[#dudes+1] = ball
end
timer.performWithDelay( 200,enemymaker2, 500 )
end
timer.performWithDelay( 0,enemymaker, 1 )
function follow(event)
for i, v in pairs(dudes) do
if dudes[i].x > 700 then
bx=dudes.x
by=dudes.y
k=Bball.x-bx,2
z=Bball.y-by,2
dudes:applyForce( k/10,z/10, dudes.x, dudes.y )
dudes[#dudes+1] = dudes
end
end
end
Runtime:addEventListener(“enterFrame”, follow)[/lua] [import]uid: 28068 topic_id: 7124 reply_id: 307124[/import]