#Failing to detect items when raycasting

38 messages · Page 1 of 1 (latest)

spare yew
#

Hi, I'm trying to have items be detected when I tap on them in AR. My input script is currently like this:

func _input(event):
    if event is InputEventScreenTouch:
        _check_for_hits(event.position)

func _check_for_hits(position: Vector2) -> void:
    if not has_session_started: return

    var camera := $ARVROrigin/ARVRCamera as Camera
    var space = camera.get_world().space
    var state = PhysicsServer.space_get_direct_state(space)
    var from = camera.project_ray_origin(position)
    var direction = camera.project_ray_normal(position)
    var result = state.intersect_ray(from, from + direction * INF)

    print(str(result.keys) + " | " + str(result.values) if result.size() > 0 else "Empty")

However, when testing on mobile, the results return empty.

#

This is how the item scene is set up

#

I have also tried InputEventMouseButton but it also doesn't seem to work so I think there's an issue in setting up the colliders or the raycast

#

Failing to detect items when raycasting

scenic brook
#

Is the box an area ?

spare yew
#

it's a staticbody

#

with a box collision shape

#

The mesh is a plane quadmesh as it is billboarding

scenic brook
#

What is the value of box collision shape extents ?

spare yew
scenic brook
#

The mesh doesnt matter really. Raycast interact with physic body / your staticbody

#

Its... Small

#

How about collision shape scale?

#

What's its value ?

spare yew
scenic brook
#

Looks good 🤔

spare yew
#

Yeah, I'm doing this in AR so having the size be 1 is way too large lol

scenic brook
#

I never do AR so I just do usually suspect
But your setup looks correct
I wonder what's wrong

spare yew
#

I've heard in a tutorial once that the physics engine doesn't really do well with super small sizes but I can't seem to find it again

scenic brook
#

I think 0.1 should be fine , but yeah my objects are bigger than that

spare yew
#

All right, I'll try scaling it up a bit then

spare yew
#

scaling it up still returns empty lol

#

There are some times that it works, however. Yesterday I was able to get a few hits before it failed to detect again

scenic brook
#

Huh? So it doesnt always empty

spare yew
#

yeah, however my setup yesterday had the rigidbody as a child of the mesh instance which someone on another server told me that the rigidbodies might be falling while leaving the mesh in place

#

so I tried to correct it today and I'm failing to get it hit haha

scenic brook
#

😂

#

Btw you leave collision layer as default ?

spare yew
#

yup, haven't changed it

scenic brook
#

And you dont change the scale of staticbody

#

Damn, I'm lost

spare yew
#

yup, I've only changed the extents

spare yew
scenic brook
#

No problem 😂

#

Can't help with anything then. Hope you find a better help. Good luck