Skip to content

Better input picking for GUI in 3D demo #769

Open
@Zireael07

Description

Which demo project is affected:
GUI in 3D

Description:
As implemented, the raycast can miss the gui since the area is very thin on Z axis. If one makes it "thicker", it will result in offset clicks, the bigger the Z axis of the area, the bigger the offset.

My solution:

# https://github.com/godotengine/godot/issues/21113#issuecomment-413839581
static func plane(normal: Vector3, p: Vector3) -> Plane:
	var n = normal.normalized()
	return Plane(n, p.dot(n))

# adjust normal to how your mesh points in global space
var plan = plane(Vector3(0,0,1), $Quad.global_transform.origin)
# you still need a ray of some sort, but instead of doing ray.get_collision_point() do this:
var cursor = plan.intersects_segment(ray.global_transform.origin, ray.global_transform * ray.cast_to)

Tested and it gets rid of the annoying offsets <3 <3

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions