How to get a collision face/surface from raycast collision normal?

Godot Version

4.3 stable

Question

How to get a collision shape surface hitted with intersect_ray? I’m making a game for a gamejam, and it has scale changing mechanic. I want to scale appropriate faces from a ray emitted from a player’s camera.
I stumbled upon this archived question:
(How can I get which face normal hit with raycast?)
And it works, but only if object has no global rotation. If say, object (cube) is rotated 90deg yaw, it’s left (-1, 0, 0) face will return back normal (0, 0, 1).

My code’s snippet:

var ray = server.intersect_ray(params)
	if not ray.is_empty():
		if ray.collider is Box:
			var box = ray.collider as Box
			box.size += abs(ray.normal)

The size in Box is Vector3.ONE that does this in _physics_process():

	collision.shape.size = size
	mesh_instance.mesh.size = size

I did it! Not exactly what i thought it be but here it is:

var face : Basis = box.global_basis.orthonormalized()
var normal = ray.normal
var direction = normal * face
var value = abs(direction)

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.