Raycasting Is Broken!

If you run the code below as per the raycasting example it all works fine:

local physics = require( "physics" ) physics.start() local ground = display.newImage( "ground.png" ) ground.x = 160 ground.y = 445 physics.addBody( ground, "static", { friction=0.5, bounce=0.3 } ) local crate1 = display.newImage( "crate.png" ) crate1.x = 120 crate1.y = 0 physics.addBody( crate1, { density=3.0, friction=0.5, bounce=0.3 } ) local crate2 = display.newImage( "crate.png" ) crate2.x = 200 crate2.y = 120 physics.addBody( crate2, { density=3.0, friction=0.5, bounce=0.3 } ) local ray = nil local from\_x = 0 local from\_y = 0 local to\_x = 320 local to\_y = 500 local unbroken\_line = display.newLine( from\_x, from\_y, to\_x, to\_y ) unbroken\_line.width = 2 unbroken\_line:setColor( 255, 0, 0 ) local gameloop = function(event)     if ray then         display.remove( ray )     end           local hits = physics.rayCast( from\_x, from\_y, to\_x, to\_y, 3 )          if hits then              print( "Hit count: ", #hits )               for i,v in ipairs(hits)         do             local object\_name             if v.object == ground then                 object\_name = "ground"             elseif v.object == crate1 then                 object\_name = "crate1"             elseif v.object == crate2 then                 object\_name = "crate2"             else                 object\_name = "unknown"             end             print( "Hit: ", i, object\_name, v.x, v.y)         end          ray = display.newLine( from\_x, from\_y, hits[1].x, hits[1].y )     else                ray = display.newLine( from\_x, from\_y, to\_x, to\_y )     end     ray.width = 2 end Runtime:addEventListener("enterFrame", gameloop)

However if you change either from_x or from_y to anything other than zero it doesn’t work.

If you change from_x from 0 to 1 you get some rather odd results.

Also rayCast does not adhere to its set length.

If you set the to_x to 160 and to_y to 240 as per above example the raycast will continue on and hit the ground, which is further away then the rayCast end point. 

Again this is a major bug!

I have submitted a bug for each of these issues.  I’m very surprised that rayCasting was released without picking up on both of these very obvious bugs. 

Hi @Icy Spark,

I pushed both of these issues to the front since (obviously) people want to start using raycasting. They should be fixed in a daily build in the next few days or so. Thanks for reporting them and the details behind each.

Brent

Many thanks Brent.  All perfect now!  Happy Face :slight_smile:

Also rayCast does not adhere to its set length.

If you set the to_x to 160 and to_y to 240 as per above example the raycast will continue on and hit the ground, which is further away then the rayCast end point. 

Again this is a major bug!

I have submitted a bug for each of these issues.  I’m very surprised that rayCasting was released without picking up on both of these very obvious bugs. 

Hi @Icy Spark,

I pushed both of these issues to the front since (obviously) people want to start using raycasting. They should be fixed in a daily build in the next few days or so. Thanks for reporting them and the details behind each.

Brent

Many thanks Brent.  All perfect now!  Happy Face :slight_smile:

Has this been resolved yet?

I’m also wondering if raycast has any other bugs in it, since started using raycasting, i’m getting frequent simulator crashes (i’m using build .1093).

Yes, it has been resolved now.

The only other bug that I can think of is that rayCast does not always return the nearest item first,  though I have programmed round that.

Here is an example for a game I’m working on at the minute.

Yes, I’m using your little bit of code and it works well, thanks for that :slight_smile:

Just seems like i’m coming across some sort of bug that is repeatedly crashing the simulator and very hard to figure out if its raycast, build .1093 or perhaps even mountain lion. However, every time, raycast is mentioned near the top of the crash thread (altho i’m no expert as to whether it will always shows near the top regardless of the crash reason):

Thread 0 Crashed:: Dispatch queue: com.apple.main-thread

0   com.coronalabs.Corona_Simulator    0x00000001000ab058 luaH_getnum + 11

1   com.coronalabs.Corona_Simulator    0x00000001000ab5d3 luaH_setnum + 31

2   com.coronalabs.Corona_Simulator    0x000000010009868b lua_rawseti + 43

3   com.coronalabs.Corona_Simulator    0x0000000100067102 0x100000000 + 422146

4   org.Box2D.Box2D                   0x00000001002694e9 b2WorldRayCastWrapper::RayCastCallback(b2RayCastInput const&, int) + 159

5   org.Box2D.Box2D                   0x00000001002693f2 void b2DynamicTree::RayCast<b2WorldRayCastWrapper>(b2WorldRayCastWrapper*, b2RayCastInput const&) const + 968

6   org.Box2D.Box2D                   0x0000000100268633 b2World::RayCast(b2RayCastCallback*, b2Vec2 const&, b2Vec2 const&) const + 57

Nice use of the reflect ray. Are you using it for pathfinding or just as part of our game mechanics?

I’m still figuring out the best way to use raycast for pathfinding.

Currently I’ve settled on dynamically building a grid map over my box2d world, ie; setting nodes that are filled with objects ‘blocked’ for calculating the basic a* path, then running my characters along the path nodes while using raycast to refine their actual paths. You heard of any better way?

Has this been resolved yet?

I’m also wondering if raycast has any other bugs in it, since started using raycasting, i’m getting frequent simulator crashes (i’m using build .1093).

Yes, it has been resolved now.

The only other bug that I can think of is that rayCast does not always return the nearest item first,  though I have programmed round that.

Here is an example for a game I’m working on at the minute.

Yes, I’m using your little bit of code and it works well, thanks for that :slight_smile:

Just seems like i’m coming across some sort of bug that is repeatedly crashing the simulator and very hard to figure out if its raycast, build .1093 or perhaps even mountain lion. However, every time, raycast is mentioned near the top of the crash thread (altho i’m no expert as to whether it will always shows near the top regardless of the crash reason):

Thread 0 Crashed:: Dispatch queue: com.apple.main-thread

0   com.coronalabs.Corona_Simulator    0x00000001000ab058 luaH_getnum + 11

1   com.coronalabs.Corona_Simulator    0x00000001000ab5d3 luaH_setnum + 31

2   com.coronalabs.Corona_Simulator    0x000000010009868b lua_rawseti + 43

3   com.coronalabs.Corona_Simulator    0x0000000100067102 0x100000000 + 422146

4   org.Box2D.Box2D                   0x00000001002694e9 b2WorldRayCastWrapper::RayCastCallback(b2RayCastInput const&, int) + 159

5   org.Box2D.Box2D                   0x00000001002693f2 void b2DynamicTree::RayCast<b2WorldRayCastWrapper>(b2WorldRayCastWrapper*, b2RayCastInput const&) const + 968

6   org.Box2D.Box2D                   0x0000000100268633 b2World::RayCast(b2RayCastCallback*, b2Vec2 const&, b2Vec2 const&) const + 57

Nice use of the reflect ray. Are you using it for pathfinding or just as part of our game mechanics?

I’m still figuring out the best way to use raycast for pathfinding.

Currently I’ve settled on dynamically building a grid map over my box2d world, ie; setting nodes that are filled with objects ‘blocked’ for calculating the basic a* path, then running my characters along the path nodes while using raycast to refine their actual paths. You heard of any better way?