I am having trouble showing the trajectory for an object. I put my code below, does anyone see what i did wrong?
[code]
–
– main.lua
_W, _H = display.contentWidth, display.contentHeight
display.setStatusBar( display.HiddenStatusBar )
local physics = require “physics”
physics.start()
physics.setScale(30)
physics.setGravity(0, 9.8) – Standard Earth gravity
physics.setDrawMode( “hybrid” )
local shape = display.newRect(0, 0, 30, 30)
shape.strokeWidth = 0
shape:setFillColor(140, 140, 140)
shape.x = 0
shape.y = 40
physics.addBody(shape, “kinematic”, { bounce = 0, friction = 0, density = 1 })
local function drawTrajectory( )
local area = shape.contentWidth / 30 * shape.contentHeight / 30
local mass = area * 1
local velocity = 200
for time=0, 10, 0.1 do
local myCircle = display.newCircle(0, 0, 4)
myCircle:setFillColor(140, 140, 140)
myCircle.x = 0 + velocity * time
myCircle.y = 40 + (9.8 * time * time / 2)
end
end
local function throw( event )
if event.phase == “ended” then
print(“THROWING”)
drawTrajectory()
shape.bodyType = “dynamic”
shape:setLinearVelocity(200, 0)
end
end
Runtime:addEventListener( “touch”, throw )
[/code] [import]uid: 26491 topic_id: 31484 reply_id: 331484[/import]