Transition.to goes THROUGH static objects? *plug n play code included* Why? Can I prevent this?

**EDIT**
I added draggable code for the big red circle, basically once you touch the big red circle, the blue square will chase you around.

What I first expected when I put this together, was the Blue Square would just “slide” down and around an object, I didn’t expect it to just go right through it. I want to allow the square to get to the Big red circle (that you drag around on screen) but only if it has a path to do so. In time I’ll have borders around the screen.

I am thinking something like if blue square is touching more than 2 objects, then calculate a new path unless the opening of another path is less than the width of the blue square.
Yea, how’s that for complicated?
Here is the code:

--The big red circle is draggable ..FYI.  
  
display.setStatusBar( display.HiddenStatusBar )  
local physics = require("physics")  
physics.start()  
physics.setScale( 60 )  
physics.setGravity( 0, 0 )  
physics.setPositionIterations(16)  
  
local game = display.newGroup();  
game.x = 0  
game.y = 0  
  
-- (Xlocation,Ylocation, Xsize, Ysize)  
local square = display.newRect (0,0,50,50)  
square:setFillColor( 0, 0, 255)   
physics.addBody( square,"dynamic",{ density = 0.1, friction=0.3, bounce=0.3, } )  
game:insert(square)  
  
local circle = display.newCircle (50,50,50,50)  
circle:setFillColor( 255, 0, 0 )   
physics.addBody( circle, "dynamic", { friction=0.3, bounce=0.3 ,radius=50} )  
circle.isBullet = true  
game:insert( circle)  
   
local topplat = display.newRect (100,200,150,50)  
topplat:setFillColor( 255, 255, 0)   
physics.addBody( topplat,"static",{friction=0.3, bounce=0.3, isGround = true } )  
game:insert(topplat)  
 topplat.rotation = 20  
topplat.isBullet = true  
   
local bottomplat = display.newRect (100,300,150,50)  
bottomplat:setFillColor( 0, 255, 0)   
physics.addBody( bottomplat,"static",{friction=0.3, bounce=0.3, isGround = true } )  
bottomplat.isBullet = true  
 game:insert(bottomplat)  
   
local target = display.newCircle (160,400,20,20)  
target:setFillColor( 255, 0, 255 )   
physics.addBody( target,"static",{ friction=0.3, bounce=0.3 ,radius=20} )  
target.isBullet = true  
 game:insert(target)  
   
   
--Spawn the square on screen so it doesn't spawn off screen :)  
square.x= math.random(square.width/2,  
display.contentWidth - square.width/2)  
square.y= math.random(square.height/2,  
display.contentHeight - square.height/2)  
  
local function dragscircle(event)  
circle.x = event.x  
circle.y = event.y  
print "Dragging Circle"  
end  
  
--Function that will have square follow circle  
local function followcircle(event)  
transition.to(square, {time=1400, y = circle.y, x = circle.x, transition = easing.linear})  
print "Circle Following Square"  
end  
  
circle:addEventListener ("touch", dragscircle)  
circle:addEventListener ("touch", followcircle)  

[import]uid: 61600 topic_id: 13801 reply_id: 313801[/import]

I think this is because transition.to is overriding physics.
if you really want to use transition you can try detecting the collision with wall and manually stop the transition.
let me know if you need further help in coding this. [import]uid: 71210 topic_id: 13801 reply_id: 50676[/import]

Ok, I updated my question and the code.
renvis@technowand I’m with you on collision detection BUT here are my constraints:

I have to find a way to include some kind of path finding. Something like if blue square touches 2 or more other objects that are NOT the red circle then find a another path, unless the path is less than the width of the square then don’t allow it.

There will be borders on all sides of the screen as well, so I guess I would have to think about "if blue square is touching a border and another object that is NOT a red circle, and the next opening available is either a border and other object that’s not a circle AND it’s width is less than that of the blue square…phew my brain hurts.

I am not sure something this crazy stupid is possible? It’s almost on the border of AI or something, I don’t know i’m too new to really know?

I know what I want to do, it’s translating it to code and figuring out what in the API I have to utilize or use something and re purpose it for something else…I don’t know. Been thinking about it all day lol.

I’m thinking transition.to is what I want to use, I don’t think I have any other options for one object following another?
Thanks for any/all ideas in advance, this is a very challenging thing for me considering how new I am hehe.

ng

:slight_smile: [import]uid: 61600 topic_id: 13801 reply_id: 50697[/import]

it is possible but not that simple to code. you have to code the enemy UI. once the square hit the wall it should find the shortest path to the object and then transition through that path.

[import]uid: 71210 topic_id: 13801 reply_id: 50700[/import]

renvis@technowand

Wow, any resources you can point me to on this? [import]uid: 61600 topic_id: 13801 reply_id: 50747[/import]

Ok, I was at the beach watching KiteBoarding (its like wakeboarding, but using a kite to pull you) and sitting on the beach I was thinking about my little problem (I think about corona 24x7 now lol).

I went ahead did some reading on collision detection, and using some examples put listeners on all the objects so it would print out what’s going on.

Now I know when things began and ended. Now I just have to figure out WHAT to do from here.

Here is what I put together, see the output in terminal window and it says what object is colliding with what.

I am thinking that anything that is a border, or an object that is not the “player” (red circle) then that will be in a group, or a table? Hmmm.

Thinking out loud here, but maybe I need a table for each level that lists the objects that are not the “player” and then call the table for…something (I don’t know what that something is")

Damn I hate being a noob!

ng

[code]

display.setStatusBar( display.HiddenStatusBar )
local physics = require(“physics”)
physics.start()
physics.setScale( 60 )
physics.setGravity( 0, 0 )
physics.setPositionIterations(16)

local game = display.newGroup();
game.x = 0
game.y = 0

– (Xlocation,Ylocation, Xsize, Ysize)
local square = display.newRect (0,0,50,50)
square:setFillColor( 0, 0, 255)
physics.addBody( square,“dynamic”,{ density = 0.1, friction=0.3, bounce=0.3, } )
square.myName = “blue Square”
game:insert(square)

–The main “Player”
local circle = display.newCircle (50,50,50,50)
circle:setFillColor( 255, 0, 0 )
physics.addBody( circle, “dynamic”, { friction=0.3, bounce=0.3 ,radius=50} )
circle.isBullet = true
circle.myName = “Red Circle”

game:insert( circle)

local topplat = display.newRect (100,200,150,50)
topplat:setFillColor( 255, 255,0)
physics.addBody( topplat,“static”,{friction=0.3, bounce=0.3, isGround = true } )
topplat.myName = “yellow platform”
topplat.rotation = 20
topplat.isBullet = true
game:insert(topplat)

local bottomplat = display.newRect (100,300,150,50)
bottomplat:setFillColor( 0, 255, 0)
physics.addBody( bottomplat,“static”,{friction=0.3, bounce=0.3, isGround = true } )
bottomplat.myName = “green platform”
bottomplat.isBullet = true
game:insert(bottomplat)

local target = display.newCircle (160,400,20,20)
target:setFillColor( 255, 0, 255 )
physics.addBody( target,“static”,{ friction=0.3, bounce=0.3 ,radius=20} )
target.myName = “Pink Circle”
target.isBullet = true
game:insert(target)

–Spawn the square on screen so it doesn’t spawn off screen :slight_smile:
square.x= math.random(square.width/2,
display.contentWidth - square.width/2)
square.y= math.random(square.height/2,
display.contentHeight - square.height/2)

local function dragscircle(event)
circle.x = event.x
circle.y = event.y
print “Dragging Circle”
end

–Function that will have square follow circle
local function followcircle(event)
transition.to(square, {time=1400, y = circle.y, x = circle.x, transition = easing.linear})
print “Circle Following Square”
end

circle:addEventListener (“touch”, dragscircle)
circle:addEventListener (“touch”, followcircle)

local function onLocalCollision( self, event )
if ( event.phase == “began” ) then

print( self.myName … ": collision began with " … event.other.myName )

elseif ( event.phase == “ended” ) then

print( self.myName … ": collision ended with " … event.other.myName )

end
end

square.collision = onLocalCollision
square:addEventListener( “collision”, square )

circle.collision = onLocalCollision
circle:addEventListener( “collision”, circle )

topplat.collision = onLocalCollision
topplat:addEventListener( “collision”, topplat )

bottomplat.collision = onLocalCollision
bottomplat:addEventListener( “collision”, bottomplat )

target.collision = onLocalCollision
target:addEventListener( “collision”, target )

[/code] [import]uid: 61600 topic_id: 13801 reply_id: 50798[/import]

just google for enemy AI follow logic. you can find some good stuffs written for flash action scripting. basic concept will be the same and its not that difficult to convert it into lua. [import]uid: 71210 topic_id: 13801 reply_id: 50800[/import]

I really wanted to create a library with game AI. I think I need to work with a flash action script developer towards that. If I get to reach there I will surely post my achievement. :slight_smile: [import]uid: 71210 topic_id: 13801 reply_id: 50822[/import]

renvis@technowand

I’ll take a look at some of that stuff. My problem is, I had zero programming experience of any kind before getting into corona sdk 89 days ago.

If there are any other tips, anyone, anytime let me know :slight_smile:
I found Dijkstra’s Algorithm seems people like to use this. I don’t know if it’s appropriate for this or not?


http://en.wikipedia.org/wiki/Dijkstra's_Algorithm

ng [import]uid: 61600 topic_id: 13801 reply_id: 50821[/import]

AI is always something I wanted to do, but I was never a programmer until trying corona sdk. My issue right now is a ton of ideas I have and trying to line up the technical ability to execute them :slight_smile:

-ng [import]uid: 61600 topic_id: 13801 reply_id: 50825[/import]

@ renvis@technowand



http://mobile.tutsplus.com/tutorials/corona/corona-sdk-game-development-path-finding/


Its a corona SDK example, using the A star algorthm. [import]uid: 61600 topic_id: 13801 reply_id: 50826[/import]

OMG ! Algorithms again ? have seen lot of AI, shortest path algorithms etc etc during my college days… but never though I will be in need of it someday… :frowning: [import]uid: 71210 topic_id: 13801 reply_id: 50827[/import]

@technowand

Are you in need of AI right now? I know I am. Maybe we can help eachother out? I am not saying that we should “share” the entire source of our projects, but sharing the pieces we have problems with I guess seems to help out a bunch.

People from this community are cool, so what I am doing is I’ll share when I get this figured out.

I am using that A star shortest path finding. Right now, it’s based on up down left right movement, but as you can see from my example of dragging and following that wouldn’t work.

I think I will start with adding diagonal movement to it. First I have to UNDERSTANT what exactly that code from that tutorial is doing…that is taking some time it’s very complex (for a newbie like me).

ng [import]uid: 61600 topic_id: 13801 reply_id: 50922[/import]

Am already working on your issue and hope to find a solution soon. I am looking at PAC man logic.but in that movement is just vertical or horizontal.no diagonal movements. Also what am thinking now is that a tile based movement will be better than x,y based movement if we are upto implementing an algorithm. Any way let me see the link you posted. Hope to get a soon soon. [import]uid: 71210 topic_id: 13801 reply_id: 50927[/import]

Technowand, that’s cool.

I am looking at my example, and looking at the link with code. The example I provide, you notice there isn’t any direction that is only left, only right, etc it’s basically like analog. The square goes where it wants. That’s what’s making this really hard.

I figured that I would have to define a board size (like in the example).

In the A star example, it seems like they hard code defined paths (up/down/left/right). So I wonder how would I define a freestyle path? meaning that the square can go anywhere it wants provided it’s on screen.

I’m tearing through the example too, I’ll post as soon as I come up with something :slight_smile:

This is a challenge, for sure!

Thanks for the help too, you’ll be in the credits with links to your projects :slight_smile: [import]uid: 61600 topic_id: 13801 reply_id: 50940[/import]

Wow, I spent about 6 hours on this and I have…nothing to post thus far.
I think it’s due to just being new to all things programming, haha. That’s ok, corona sdk is fun to play with, until it makes you made and you can’t figure out something to save your life!
[import]uid: 61600 topic_id: 13801 reply_id: 51169[/import]

http://developer.anscamobile.com/code/pathfinding-demo#comment-53866
Renvis, I just found this posted a day ago for A*.

Also, I bought your Corona book. Good so far, when you guys going to update? :slight_smile:
ng [import]uid: 61600 topic_id: 13801 reply_id: 53868[/import]

http://developer.anscamobile.com/code/pathfinding-demo#comment-53866
Renvis, I just found this posted a day ago for A*.

Also, I bought your Corona book. Good so far, when you guys going to update? :slight_smile:
ng [import]uid: 61600 topic_id: 13801 reply_id: 53869[/import]