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