Undocumented Function: rayCastObject() is functional and can be used!
-
Hi folks - bit of a small announcement. I am excited to say that after some testing prompted by a few different things, the function
raycastObject()
is actually far more functional than we thought.The function
raycast()
however is not working properly and should not be used. It is highly likely that this function gets re-purposed and improved, so please avoid using it.However, I urge you to have a play with
raycastObject()
as it can do some powerful things.If you aren't aware - the function is for use in 3D programs, and tells you the distance between a point in space and the point at which object geometry is intersected in a direction.
For example, let's say we have a player at world space {0, 0, 0}, and a building object in the distance at {0, 0, 30}. We can raycast from {0, 0, 0} in a direction of {0, 0, 1} and we will get the distance between our origin point and the point at which we touch the building. The awesome thing here is that we are talking about the building geometry itself, not the collision box!
Using this I have whipped up quite a solid collision check in the KatRacer program, purely by raycasting to the level from the car.
Syntax:
dist = raycastObject(object_to_check, origin_position, direction)
The weakness of this function is that it must be told which object you'd like to raycast to, which isn't very helpful if you've got tons of objects being thrown around the game world, but in cases where you have single large world object (like Kat's Race Tracks or Stadiums), or when you know exactly the object you want to check, it gives you extremely precise information.
For
raycast()
, it should simply interact with all geometry in your game world, but it currently does not. We will fix this at some stage when we can dedicate time to it, and hopefully improve the function somewhat too, providing extra data for ease of use. Until this is fixed, please do not useraycast()
As is the case with undocumented functions, it must be understood that these are far less tested than the documented functions and as such don't expect perfect performance. I can see already that it is quite taxing for the console, and so it becomes more econimical to stagger the checks between frames. We will be improving this, fear not!
Hope this was of some use to a few users. I know raycast() has come up a few times on the forum and I wanted to get some definitive information out there.
-
Awesome! What a nice surprise.
-
hmmm... how interesting I will experiment with it and see what i can do.
-
Very good news ! I'm working on a car racing project... Congratulations to the team for the job!
-
-
@vincent2105 wow! I'm very curious about how you implemented this as the performance is very high and you have tons of objects! Any chance we could see the project?
-
@dave Thank you ! I'll share the program when it's finished. However, it's not complicated, everything is based on a tilemap. I have one object per square. I calculate the position of the player within this tilemap then I use the rayCastObject() function on the squares adjacent to the player only, i.e. 9 tests in all. The problem arises with objects that overlap several squares like bridges for example... I'm thinking of isolating the treatment of these very large objects or, if not, testing more squares around the player... I have to try more thoroughly to see if performance suffers too much.
-
This rayCastObject function is really amazing! By treating very large objects separately, I can now use bridges, and other objects that have slopes... To do this, I first place the very large object within the map. Then, in the tilemap, I give each tile overlapped by this large object the same index, so I only need to call the rayCastObject() function once since I know my position within the tilemap! I just have to resize the large objects so that their edges coincide perfectly with the squares of the tilemap, especially when 2 large objects are side by side. I think I'll open a topic soon to talk about my project :)