Hi guys, i would like to create a small tank, however i cant figure out how to do the tracks.
Does anybody know how to go about this or have an example?
Thanks in advance [import]uid: 162458 topic_id: 30921 reply_id: 330921[/import]
Hi guys, i would like to create a small tank, however i cant figure out how to do the tracks.
Does anybody know how to go about this or have an example?
Thanks in advance [import]uid: 162458 topic_id: 30921 reply_id: 330921[/import]
Depends what sort of view it is: top down or side on? I’m assuming you mean side on, so you would want to create the tracks as (probably) separate pieces connected at each end. Take a look at the bridge physics sample in the Corona SDK samples directory. [import]uid: 8271 topic_id: 30921 reply_id: 123669[/import]
Thanks.
Its side on. Iv taken a look at the bridge example, but how would i loop the track so it connects to itself and then move depending on the wheels? [import]uid: 162458 topic_id: 30921 reply_id: 123671[/import]
Just position the pieces and create the joints all the way round. [import]uid: 8271 topic_id: 30921 reply_id: 123672[/import]
Thanks, a little closer but no cigar.
here is the code i have so far
[code]local storyboard = require( “storyboard” )
local scene = storyboard.newScene()
display.setStatusBar( display.HiddenStatusBar )
require “physics”
physics.start()
–physics.setGravity(0, 1.5)
physics.setDrawMode(“hybrid”)
local function dragItem(item)
–Add simple drag/drop functionality to passed item
return function(event)
local item = event.target
local phase = event.phase
if “began” == phase then
display.getCurrentStage():setFocus( item )
– Store initial position
item.x0 = event.x - item.x
item.y0 = event.y - item.y
else
if “moved” == phase then
item.x = event.x - item.x0
item.y = event.y - item.y0
elseif “ended” == phase or “cancelled” == phase then
display.getCurrentStage():setFocus( nil )
end
end
– Stop further propagation of touch event!
return true
end
end
local circle1 = display.newCircle( 125, 126, 10 )
local circle2 = display.newCircle( 227, 126 ,10 )
circle1:setFillColor(25,128,25)
circle2:setFillColor(25,25,200)
physics.addBody(circle1,“kinematic”,{density=0,friction=0,bounce=0})
physics.addBody(circle2,“kinematic”,{density=0,friction=0,bounce=0})
circle1:addEventListener(“touch”, dragItem(circle1))
circle2:addEventListener(“touch”, dragItem(circle2))
local track1 = display.newImageRect( “board.png”, 30, 12 )
track1:setReferencePoint(display.CenterReferencePoint)
track1.x = 120
track1.y = 121
physics.addBody( track1, { density=0.8, friction=0.3, bounce=0.3 } )
local track2 = display.newImageRect( “board.png”, 30, 12 )
track2:setReferencePoint(display.CenterReferencePoint)
track2.x = 150
track2.y = 121
physics.addBody( track2, { density=0.8, friction=0.3, bounce=0.3 } )
joint2 = physics.newJoint( “pivot”, track1, track2, track1.x, track1.y )
local track3 = display.newImageRect( “board.png”, 30, 12 )
track3:setReferencePoint(display.CenterReferencePoint)
track3.x = 180
track3.y = 121
physics.addBody( track3, { density=0.8, friction=0.3, bounce=0.3 } )
joint3 = physics.newJoint( “pivot”, track2, track3, track2.x, track2.y )
local track4 = display.newImageRect( “board.png”, 30, 12 )
track4:setReferencePoint(display.CenterReferencePoint)
track4.x = 210
track4.y = 121
physics.addBody( track4, { density=0.8, friction=0.3, bounce=0.3 } )
joint4 = physics.newJoint( “pivot”, track3, track4, track3.x, track3.y )
local track5 = display.newImageRect( “board.png”, 30, 12 )
track5:setReferencePoint(display.CenterReferencePoint)
track5.x = 239
track5.y = 129
track5.rotation = 45
physics.addBody( track5, { density=0.8, friction=0.3, bounce=0.3 } )
joint5 = physics.newJoint( “pivot”, track4, track5, track4.x, track4.y )
local track6 = display.newImageRect( “board.png”, 30, 12 )
track6:setReferencePoint(display.CenterReferencePoint)
track6.x = 239
track6.y = 151
track6.rotation = -45
physics.addBody( track6, { density=0.8, friction=0.3, bounce=0.3 } )
joint6 = physics.newJoint( “pivot”, track5, track6, track5.x, track5.y )
local track7 = display.newImageRect( “board.png”, 30, 12 )
track7:setReferencePoint(display.CenterReferencePoint)
track7.x = 210
track7.y = 159
physics.addBody( track7, { density=0.8, friction=0.3, bounce=0.3 } )
joint7 = physics.newJoint( “pivot”, track6, track7, track6.x, track6.y )
local track8 = display.newImageRect( “board.png”, 30, 12 )
track8:setReferencePoint(display.CenterReferencePoint)
track8.x = 181
track8.y = 159
physics.addBody( track8, { density=0.8, friction=0.3, bounce=0.3 } )
joint8 = physics.newJoint( “pivot”, track7, track8, track7.x, track7.y )
local track9 = display.newImageRect( “board.png”, 30, 12 )
track9:setReferencePoint(display.CenterReferencePoint)
track9.x = 151
track9.y = 159
physics.addBody( track9, { density=0.8, friction=0.3, bounce=0.3 } )
joint9 = physics.newJoint( “pivot”, track8, track9, track8.x, track8.y )
local track10 = display.newImageRect( “board.png”, 30, 12 )
track10:setReferencePoint(display.CenterReferencePoint)
track10.x = 121
track10.y = 159
physics.addBody( track10, { density=0.8, friction=0.3, bounce=0.3 } )
joint10 = physics.newJoint( “pivot”, track9, track10, track9.x, track9.y )
local track11 = display.newImageRect( “board.png”, 30, 12 )
track11:setReferencePoint(display.CenterReferencePoint)
track11.x = 92
track11.y = 151
track11.rotation = 45
physics.addBody( track11, { density=0.8, friction=0.3, bounce=0.3 } )
joint11 = physics.newJoint( “pivot”, track10, track11, track10.x, track10.y )
local track12 = display.newImageRect( “board.png”, 30, 12 )
track12:setReferencePoint(display.CenterReferencePoint)
track12.x = 91
track12.y = 129
track12.rotation = -45
physics.addBody( track12, { density=0.8, friction=0.3, bounce=0.3 } )
joint12 = physics.newJoint( “pivot”, track11, track12, track11.x, track11.y )
joint1 = physics.newJoint( “pivot”, track12, track1, track12.x, track12.y )
return scene[/code] [import]uid: 162458 topic_id: 30921 reply_id: 123680[/import]
Here’s a Box2d example that you might get some inspiration from:
YouTube Video:
http://www.youtube.com/watch?v=0awh5MFJwQo#t=2m12s
Accompanying Tutorial/Discussion:
http://www.iforce2d.net/b2dtut/conveyor-belts [import]uid: 74503 topic_id: 30921 reply_id: 123699[/import]
Thanks for the links but this is still confusing the life out of me. I just cant see how it works
[import]uid: 162458 topic_id: 30921 reply_id: 123800[/import]
Start with a series of small rectangles connected by pivot joints. Then curve them around until they link together. Think about how a real tank’s tracks are created. [import]uid: 8271 topic_id: 30921 reply_id: 123823[/import]
Depends what sort of view it is: top down or side on? I’m assuming you mean side on, so you would want to create the tracks as (probably) separate pieces connected at each end. Take a look at the bridge physics sample in the Corona SDK samples directory. [import]uid: 8271 topic_id: 30921 reply_id: 123669[/import]
Thanks.
Its side on. Iv taken a look at the bridge example, but how would i loop the track so it connects to itself and then move depending on the wheels? [import]uid: 162458 topic_id: 30921 reply_id: 123671[/import]
Just position the pieces and create the joints all the way round. [import]uid: 8271 topic_id: 30921 reply_id: 123672[/import]
Thanks, a little closer but no cigar.
here is the code i have so far
[code]local storyboard = require( “storyboard” )
local scene = storyboard.newScene()
display.setStatusBar( display.HiddenStatusBar )
require “physics”
physics.start()
–physics.setGravity(0, 1.5)
physics.setDrawMode(“hybrid”)
local function dragItem(item)
–Add simple drag/drop functionality to passed item
return function(event)
local item = event.target
local phase = event.phase
if “began” == phase then
display.getCurrentStage():setFocus( item )
– Store initial position
item.x0 = event.x - item.x
item.y0 = event.y - item.y
else
if “moved” == phase then
item.x = event.x - item.x0
item.y = event.y - item.y0
elseif “ended” == phase or “cancelled” == phase then
display.getCurrentStage():setFocus( nil )
end
end
– Stop further propagation of touch event!
return true
end
end
local circle1 = display.newCircle( 125, 126, 10 )
local circle2 = display.newCircle( 227, 126 ,10 )
circle1:setFillColor(25,128,25)
circle2:setFillColor(25,25,200)
physics.addBody(circle1,“kinematic”,{density=0,friction=0,bounce=0})
physics.addBody(circle2,“kinematic”,{density=0,friction=0,bounce=0})
circle1:addEventListener(“touch”, dragItem(circle1))
circle2:addEventListener(“touch”, dragItem(circle2))
local track1 = display.newImageRect( “board.png”, 30, 12 )
track1:setReferencePoint(display.CenterReferencePoint)
track1.x = 120
track1.y = 121
physics.addBody( track1, { density=0.8, friction=0.3, bounce=0.3 } )
local track2 = display.newImageRect( “board.png”, 30, 12 )
track2:setReferencePoint(display.CenterReferencePoint)
track2.x = 150
track2.y = 121
physics.addBody( track2, { density=0.8, friction=0.3, bounce=0.3 } )
joint2 = physics.newJoint( “pivot”, track1, track2, track1.x, track1.y )
local track3 = display.newImageRect( “board.png”, 30, 12 )
track3:setReferencePoint(display.CenterReferencePoint)
track3.x = 180
track3.y = 121
physics.addBody( track3, { density=0.8, friction=0.3, bounce=0.3 } )
joint3 = physics.newJoint( “pivot”, track2, track3, track2.x, track2.y )
local track4 = display.newImageRect( “board.png”, 30, 12 )
track4:setReferencePoint(display.CenterReferencePoint)
track4.x = 210
track4.y = 121
physics.addBody( track4, { density=0.8, friction=0.3, bounce=0.3 } )
joint4 = physics.newJoint( “pivot”, track3, track4, track3.x, track3.y )
local track5 = display.newImageRect( “board.png”, 30, 12 )
track5:setReferencePoint(display.CenterReferencePoint)
track5.x = 239
track5.y = 129
track5.rotation = 45
physics.addBody( track5, { density=0.8, friction=0.3, bounce=0.3 } )
joint5 = physics.newJoint( “pivot”, track4, track5, track4.x, track4.y )
local track6 = display.newImageRect( “board.png”, 30, 12 )
track6:setReferencePoint(display.CenterReferencePoint)
track6.x = 239
track6.y = 151
track6.rotation = -45
physics.addBody( track6, { density=0.8, friction=0.3, bounce=0.3 } )
joint6 = physics.newJoint( “pivot”, track5, track6, track5.x, track5.y )
local track7 = display.newImageRect( “board.png”, 30, 12 )
track7:setReferencePoint(display.CenterReferencePoint)
track7.x = 210
track7.y = 159
physics.addBody( track7, { density=0.8, friction=0.3, bounce=0.3 } )
joint7 = physics.newJoint( “pivot”, track6, track7, track6.x, track6.y )
local track8 = display.newImageRect( “board.png”, 30, 12 )
track8:setReferencePoint(display.CenterReferencePoint)
track8.x = 181
track8.y = 159
physics.addBody( track8, { density=0.8, friction=0.3, bounce=0.3 } )
joint8 = physics.newJoint( “pivot”, track7, track8, track7.x, track7.y )
local track9 = display.newImageRect( “board.png”, 30, 12 )
track9:setReferencePoint(display.CenterReferencePoint)
track9.x = 151
track9.y = 159
physics.addBody( track9, { density=0.8, friction=0.3, bounce=0.3 } )
joint9 = physics.newJoint( “pivot”, track8, track9, track8.x, track8.y )
local track10 = display.newImageRect( “board.png”, 30, 12 )
track10:setReferencePoint(display.CenterReferencePoint)
track10.x = 121
track10.y = 159
physics.addBody( track10, { density=0.8, friction=0.3, bounce=0.3 } )
joint10 = physics.newJoint( “pivot”, track9, track10, track9.x, track9.y )
local track11 = display.newImageRect( “board.png”, 30, 12 )
track11:setReferencePoint(display.CenterReferencePoint)
track11.x = 92
track11.y = 151
track11.rotation = 45
physics.addBody( track11, { density=0.8, friction=0.3, bounce=0.3 } )
joint11 = physics.newJoint( “pivot”, track10, track11, track10.x, track10.y )
local track12 = display.newImageRect( “board.png”, 30, 12 )
track12:setReferencePoint(display.CenterReferencePoint)
track12.x = 91
track12.y = 129
track12.rotation = -45
physics.addBody( track12, { density=0.8, friction=0.3, bounce=0.3 } )
joint12 = physics.newJoint( “pivot”, track11, track12, track11.x, track11.y )
joint1 = physics.newJoint( “pivot”, track12, track1, track12.x, track12.y )
return scene[/code] [import]uid: 162458 topic_id: 30921 reply_id: 123680[/import]
Here’s a Box2d example that you might get some inspiration from:
YouTube Video:
http://www.youtube.com/watch?v=0awh5MFJwQo#t=2m12s
Accompanying Tutorial/Discussion:
http://www.iforce2d.net/b2dtut/conveyor-belts [import]uid: 74503 topic_id: 30921 reply_id: 123699[/import]
Thanks for the links but this is still confusing the life out of me. I just cant see how it works
[import]uid: 162458 topic_id: 30921 reply_id: 123800[/import]
Start with a series of small rectangles connected by pivot joints. Then curve them around until they link together. Think about how a real tank’s tracks are created. [import]uid: 8271 topic_id: 30921 reply_id: 123823[/import]