Lua waypoints

Hey everyone, I’ve been having some trouble on this little project I’ve been working on. I am new to Lua and mobile game designing in general, but that isn’t the issue on hand. What I’m trying to accomplish is a waypoint system, the best example I could give would be like a tower defense game. The enemies move on a certain path or to waypoints. I have my arrays.

wp\_x = { 20, 40, 60, 80, 100 }  
wp\_y = { 100, 80, 60, 40, 20 }  

I have tried a few if statements, they don’t work they way I want, this is what I’ve tried.

if enem.x = wp\_x[1] then enem.x = wp\_x[2]  

Ect. I had my doubts with that, because of the fact I pretty much knew it wouldn’t show my entity moving to that coord.

I have also tried transition.to, this was my code.

transition.to(enem, { time = 2500, wp\_x[2], wp\_y[2] })  

Which did nothing at all. Any ideas? Thanks. [import]uid: 45981 topic_id: 7941 reply_id: 307941[/import]

[lua]transition.to(enem, { time = 2500, x=wp_x[2], y=wp_y[2] })[/lua] [import]uid: 6645 topic_id: 7941 reply_id: 28266[/import]

if enem.x == wp\_x[1] then enem.x = wp\_x[2] end

Hi.

i tried something.
perhaps it helps you.

[lua]-- waypoint test
– 110318,sidasa

–local start_x = 0
–local start_y = 0

– variables
local start_x = display.contentWidth/2
local start_y = display.contentHeight/2

local i = 0

wp_x = { 20, 40, 60, 80, 100 }
wp_y = { 100, 80, 60, 40, 20 }
– show image
enemy = display.newImage(“enemy.png”)
enemy.x = start_x
enemy.y = start_y
– move image to next waypoint
local function nextWaypoint ()
transition.to( enemy, { x=wp_x[i], y=wp_y[i] } )
end
local function touched ( event )
print( "i: " … i ) – console test output
if event.phase == “ended” then
i = i+1
nextWaypoint()
end
end

Runtime:addEventListener(“touch”, touched)[/lua]

in my example, the enemy moved to the next waypoint, when you touch the display. [import]uid: 42078 topic_id: 7941 reply_id: 28433[/import]

Ok, this is hilarious, but please take this lightly.

My definition of waypoint way off…

See http://www.youtube.com/watch?v=TZ_AH4Iy-z4

A waypoint is commonly associated with GPS for inclusion of longitude, latitude and altitude.

So when I read the forum titile, then @amf.studios entry “am new to lua” … and I been working with objects along a bezier path, here I was, oh, cool maybe I get motivated to do my bez example like the video above.

LOL !

I thought it was funny.

C.
[import]uid: 24 topic_id: 7941 reply_id: 28680[/import]

Is there a way to rotate the enemy at certain way-points? [import]uid: 135121 topic_id: 7941 reply_id: 93775[/import]