Player Raycast does not return expected coordinates

  • Playing around with the API, I have this bit of code :



    (Don't mind the commented lines.)


    And here is getWorldData



    (Again, don't mind other pieces of the code, suffices to say that getBlockTypeAndId returns the absolute block id into a type and texture id, etc.)


    However, I always get Terrain=0 and Block=block 0. So, is the hit position represented by raycastResult.collisionPoint a position before hitting something, or am I missing something? How do I get the block position where the collision occurs?

  • Thanks!


    I also thought that the collision might occur right before the specific location (i.e. to place lights, etc.) so I tried changing the line 3 of the first source code provided like so


    Code
    local worldData = getWorldData(event.player:getPosition():add(event.player:getViewDirection():mult(raycastResult.distance + 0.2)));


    to make the actual hit test a little further, but no real change. I did get a correct result at a very specific location, but I'm not sure why. Since I need to restart the game every time I change a little thing, this debugging is too time consuming for me at the moment.


    Having a debugging console (writing commands into the Lua console) would be quite useful :)

Participate now!

Don’t have an account yet? Create a new account now and be part of our community!