Barycentric Coordinates from Raycasting to calculate any Tri-Mesh face's position and rotation for smooth movement on floors, walls, or rollercoaster-like paths, (A.K.A. Anti-Gravity or Wallwalking) #4663
Labels
Milestone
Describe the project you are working on
This is a side project that I mess around on my free time: "A futuristic driving simulation within Godot that emulates anti-gravity physics such as F-Zero"
Link to demo-project (Currently Broken): https://github.com/Corruptinator/G-Zero [Admittedly I haven't analyzed/looked at this in years]
Describe the problem or limitation you are having in your project
Godot currently has no function to allow objects to optimally rotate/allign the object based on where raycast is colliding on any mesh or tri-mesh's normals.
Describe the feature / enhancement and how it helps to overcome the problem or limitation
I think what will help is the ability to utilize Barycentric Coordinates in any Raycast nodes, which will calculate the position of any Tri-Mesh's point using the Tri-Mesh face's vertices to determine the point of position and rotation:
Here are two videos that made me realize that Barycentric Coordinates from raycasting has potential:
https://www.youtube.com/watch?v=Oj_eBEVNZ6o (Low-Poly Mesh driving Example)
https://www.youtube.com/watch?v=UhJUn3vyPx8 (F-Zero Driving Physics using Barycentric Coordinates Unity Example)
Based on the two videos I've ran into and analyzed the way the process works (even on Low-Poly meshes) it uses the vertices from the face normal (Must be triangle/tri) and interpolate them with the barycentric coordinates to calculate the rotation, position, and movement.
This would help overcome the problem of finding a way for movable objects such as flying cars or wall walking characters to move and rotate optimally based on the tri-mesh's normals, even on walls (A.K.A. F-Zero or Super Mario Galaxy).
Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams
The way I see how it will work is that 3D raycast will utilize an additional function, whether the raycast is colliding against the object or not: raycast.get_barycentric_coordinates(), then it will calculate the tri-face normal using the 3 vertices from their own global_position, and calculate the point through this formula: P = uA + vB + wC
P.S. (Colliding mesh must be "Tri-Mesh"! and the raycast must also determine whether the normal is Triangle, not Quad or N-Gon it is based on the colliding mesh)
Next we can interpolate the normal from the same raycast onto the forumated barycentric coordinates to get the results:
(Pseudo Code):
If this enhancement will not be used often, can it be worked around with a few lines of script?
"There is currently no script alternative that will make the Barycentric Coordinate interpolation/calculation work..."
Is there a reason why this should be core and not an add-on in the asset library?
"This would allow users to utilize the ability to allow objects to be capable of traversing/explore around not only on floors but on walls. (As mentioned: Anti-Gravity/ Wallwalking)
The text was updated successfully, but these errors were encountered: