– This turned out to be a long post – :rolleyes:
I had my user_tank set to user_tank.class = “Player”
My enemy-tanks, IGmines and a few other objects also had a defined .class
I added the .objType to the following objects - just to see if they would actually register in the terminal when hit:
[lua]
user_tank.objType = “PlayerTank”
user_turret.objType = “PlayerTank”
enemyB02.objType = “EnemyTank”
ET02radar.objType = “Radar”
[/lua]
And here is all of the code that deals with the ray
[lua]
E1Dray = physics.rayCast( enemyB02.x - 50, enemyB02.y, user_tank.x, user_tank.y, “sorted” )
local hitFirst = E1Dray[1]
local hitX, hitY = hitFirst.position.x, hitFirst.position.y
DRline = display.newLine( enemyB02.x - 50, enemyB02.y, user_tank.x, user_tank.y )
DRline.width = 10
DRline:setColor( 255,50,40,100 )
DRline.blendMode = “add”
level1group:insert( DRline )
if E1Dray then
– There’s at least one hit.
print( "Hit count: " … tostring( #E1Dray ) )
– Output all the results.
for i,v in ipairs(E1Dray) do
print( "Hit: ", i, object_name, " Position: ", v.position.x, v.position.y, " Surface normal: ", v.normal.x, v.normal.y )
end
print( "The first object hit is: ",
E1Dray[1].object, " at position: ", E1Dray[1].position.x, E1Dray[1].position.y, " where the surface normal is: ", E1Dray[1].normal.x, E1Dray[1].normal.y )
else
– There’s no hit.
end
if ( E1Dray[1].objType and E1Dray[1].objType == “PlayerTank” ) then
[/lua]
Using all that code, this is what the terminal window prints - based on the conditions in this photo
2013-06-21 12:33:52.560 Corona Simulator[23416:f03] Hit count: 2
2013-06-21 12:33:52.560 Corona Simulator[23416:f03] Hit: 1 nil Position: 365.51693725586 387.89959716797 Surface normal: 0.56341761350632 0.82617217302322
2013-06-21 12:33:52.560 Corona Simulator[23416:f03] Hit: 2 nil Position: 355.6755065918 393.59799194336 Surface normal: 0.89465683698654 -0.44675385951996
2013-06-21 12:33:52.561 Corona Simulator[23416:f03] The first object hit is: table: 0x10e4fbad0 at position: 365.51693725586 387.89959716797 where the surface normal is: 0.56341761350632 0.82617217302322
The ray seems to only register a hit for the user_tank and user_turret (both with the same objType) which to me would make perfect sense, but it still won’t fire even though it’s hitting the PlayerTank. :wacko:
P.S. When I removed the - 50 from the ray and line (to make it originate from within the enemy-tank) the terminal still printed the exact same thing.