I'm trying to implement a simple tile-based editor using RayCast. What I'm doing is simply performing a raycast from the mouse, and then flooring down the result:
var mouse = get_viewport().get_mouse_position()
translation = camera.project_ray_origin(mouse)
cast_to = camera.project_ray_normal(mouse) * ray_length
target_position = get_collision_point().floor()
target_normal = get_collision_normal().round()
ghost.translation = target_position
The problem is that due to float imprecisions, the floored raycast result ends up jerking around a lot, and it's generally quite annoying to place blocks as sometimes the result ends up being inside of my floor cube mesh.
Is there any fairly clean way I can solve this?