[ad_1]

I’ve tried to ray forged my mouse place to Sprite3D on display screen however I’ve some issues with it.

func _input(occasion):
    if occasion is InputEventMouse:
        mouse = occasion.place
    if occasion is InputEventMouseButton and occasion.pressed:
        if occasion.button_index == MOUSE_BUTTON_LEFT:
            get_selection()

func get_selection():
    var worldspace = participant.camera_3d.get_world_3d().direct_space_state
    var begin = participant.camera_3d.project_ray_origin(mouse)
    var finish = participant.camera_3d.project_position(mouse, 1000)
    
    var question = PhysicsRayQueryParameters3D.create(begin, finish)

    var consequence = worldspace.intersect_ray(question)

Temporary setting of my challenge
My character/enemy is a Sprite3D in CharacterBody3D with small collision field solely on its ft. I would like the mouse to detect the form of coloured pixels of my character/enemy I noticed on display screen however intersect_ray() at all times return with collider within the object, so it went by the character to the ground object as an alternative.

Why I do not set the collision field to match the peak of sprite?
Digital camera is connected to participant with 45 diploma angle trying right down to the participant and it may well zoom-in-out and tilt then it’s going to look_at() participant once more at its new place. Whereas tilting, character’s visible can also be tilted to parallel with digicam. So I feel its collision field could not be the identical measurement as sprite as a result of sprite’s peak will probably be altering on a regular basis and collision field can’t be tilted into the bottom too.

visuals.rotation.x = camera_3d.rotation.x

So my query is…
Is there a method to do a handbook raycasting? or to calculate coloured pixels’ positions from characters/enemy on display screen evaluate to mouse place and know if it is participant or enemy. Please understand that digicam can zoom-in or zoom-out and tilting.

Thanks upfront

[ad_2]

Leave a Reply

Your email address will not be published. Required fields are marked *