![]() |
Attention | Topic was automatically imported from the old Question2Answer platform. |
![]() |
Asked By | lqdev |
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:
func _physics_process(_delta):
var mouse = get_viewport().get_mouse_position()
translation = camera.project_ray_origin(mouse)
cast_to = camera.project_ray_normal(mouse) * ray_length
force_raycast_update()
if is_colliding():
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?
(moved to answers)
lqdev | 2021-01-25 10:07