I posted this in the code exchange comments section but I figured my problem might get more visibility here in the forum. I downloaded the Flight Path sample app a couple of days ago just after I downloaded corona. I found a problem that I can’t figure out, and I’ve digging through the code line by line. Sometimes (actually pretty often), the planes lose their path after the path’s been drawn. They go off-screen in a straight line, and the path line remains on-screen. It *appears* to happen more often when the path of different planes intersect at some point, but I’ve also seen it happen sporadically. I started echoing the x,y values of the plane’s paths on the terminal but everything seems normal. Any help in solving this would be much appreciated. It’s driving me batty. [import]uid: 80305 topic_id: 13364 reply_id: 313364[/import]
Hi, have you found any solution to this issue? [import]uid: 70056 topic_id: 13364 reply_id: 75654[/import]
Yeah, I think I did, but it’s a bit hackish. I’m away from a computer for the weekend but can post the code snippet on Monday. [import]uid: 80305 topic_id: 13364 reply_id: 75666[/import]
That would be great. Thanks!. [import]uid: 70056 topic_id: 13364 reply_id: 75717[/import]
You probably saw that I entered some links on there for greater explanation on Catmull splines.I too noticed this and am looking to correct the initial ansca sample code and simplify in my version.
While I’m not completely focused on this I think that the issue is around the points are removed before the object has had chance to follow. Specifically where I am yet to find but will report back [import]uid: 103970 topic_id: 13364 reply_id: 75796[/import]
Thanks mygamingproject! Do report back your findings. =) I am cracking my head over this as well. [import]uid: 70056 topic_id: 13364 reply_id: 76077[/import]
Sorry, I had to put out a couple of fires in my day job and didn’t have time to post before.
What I discovered was that the planes were losing their path when the velocity in the x or y direction was zero, or very close to zero. Turns out you can easily cause them to go bonkers if you draw paths at right angles, which I discovered after much trial and error. What I *think* is happening is that one of the angle calculations is returning bad data with this zero velocity. That’s one of the things I’ll try to figure out next, but for the time being what I’m doing is setting the velocity to non zero in the event the plane is moving orthogonal to either axis.
In the gameScreen.lua file I added the block between the asterisks in the followPoints(plane) function:
point = plane.points[1]
local flightAngle = math.atan2((plane.y - point.y) , (plane.x - point.x) ) \* (180 / math.pi)
local velocityX = math.cos(math.rad(flightAngle)) \* planeSpeed \* -1
local velocityY = math.sin(math.rad(flightAngle)) \* planeSpeed \* -1
plane.rotation = flightAngle - 90
---[[ \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*
-- add this to set the velocity to non zero
if(velocityX \> -0.1 and velocityX \<= 0) then
velocityX = -1
end
if(velocityX \< 0.1 and velocityX \>= 0) then
velocityX = 1
end
if(velocityY \> -0.1 and velocityY \<= 0) then
velocityY = -1
end
if(velocityY \< 0.1 and velocityY \>= 0) then
velocityY = 1
end
--\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*
--]]
plane:setLinearVelocity( velocityX, velocityY)
--print(velocityX)
--print(velocityY)
local enterFrameFunction = nil
local checkForNextPoint
checkForNextPoint = function(plane)
I also have the modified code here http://www.box.com/s/ym80vh387eynuu2ly7mh but I’ve modified it for debugging purposes, for instance I only have two planes spawning and am not displaying the background. Again, you can test it by drawing paths that have right angle turns.
Hope it helps. [import]uid: 80305 topic_id: 13364 reply_id: 76473[/import]
Thanks for sharing, Insurgent Pixel. I will try it out. =) [import]uid: 70056 topic_id: 13364 reply_id: 76825[/import]
I have found that this is due to a velocity too close to zero.
Solution 1
To correct this I added code to the followPoints(plane) method to ensure a high enough velocity.
Original Code:
local flightAngle = math.atan2((plane.y - point.y) , (plane.x - point.x) ) \* (180 / math.pi)
local velocityX = math.cos(math.rad(flightAngle)) \* planeSpeed \* -1
local velocityY = math.sin(math.rad(flightAngle)) \* planeSpeed \* -1
Modified Code:
local flightAngle = math.atan2((plane.y - point.y) , (plane.x - point.x) ) \* (180 / math.pi)
local velocityX = math.cos(math.rad(flightAngle)) \* planeSpeed \* -1
local velocityY = math.sin(math.rad(flightAngle)) \* planeSpeed \* -1
while(math.abs(velocityX) \< 0.001)do
velocityX = velocityX \* 10
end
while(math.abs(velocityY) \< 0.001)do
velocityY = velocityY \* 10
end
Solution 2
To correct this I modified code in the checkForNextPoint method. The new code only checks if the plane is close enough to the point, not if it has passed it.
Original Code:
if( (velX \< 0 and plane.x \< dest.x and velY \< 0 and plane.y \< dest.y) or (velX \> 0 and plane.x \> dest.x and velY \< 0 and plane.y \< dest.y) or
(velX \> 0 and plane.x \> dest.x and velY \> 0 and plane.y \> dest.y) or (velX \< 0 and plane.x \< dest.x and velY \> 0 and plane.y \> dest.y) or #plane.points == 0) then
Modified Code:
if( (math.abs(dest.x - plane.x) \< 1) and (math.abs(dest.y - plane.y) \< 1) or #plane.points == 0) then
[import]uid: 139413 topic_id: 13364 reply_id: 107458[/import]