RaycastFromWorldPosition - Not Starting From Given Position

  • Hi again. This time I'm trying to spawn some mobs around the player under certain conditions. I'm taking the player's position, adding some random X and Z values, and then using that new position spawnPosition as the starting position for the raycastFromWorldPosition() method. Basically I'm trying to find the ground level Y value so that I can spawn a mob at the spawnPosition vector at the correct terrain height. However, no matter what I use as the starting position vector, it only uses the player's position vector.

    My vectors look good to start with.

    But after the ray cast, the spawn point is off.

    I'm guessing another bug? Or, hopefully, I'm missing something obvious in my code and it can be salvaged. Maybe my direction vector is wrong? Any help would be much appreciated.

  • It's indeed a bug 8| :/ I'm sorry about that, it's really a pity these bugs stayed under the radar for so long... these bugs will be definitely fixed in the new version though (once the Plugin API becomes available there) ;)

    We will also fix them once we release a new update for the Java version, but currently we have no ETA for that yet...

  • No worries. :D

    Is there perhaps some way of getting the terrain Y value at specific X,Z values? That's basically what I'm trying to do. If the ray cast won't work, maybe there is another way?


    Edit: Actually I think I have figured another way to do it; a kind of voxel cast. Find the chunk at position X,Z, find the local block coords for the position's X,Z, start at the highest Y value and get the terrain id. If it's air, go down 1 and test the terrain id again. Once it hits not-air, I've probably found the surface. It'll take a bit of finessing to avoid structures and other things, but it might work.

Participate now!

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