I've tried to ray cast my mouse position to Sprite3D on screen but I have some problems with it.
if event is InputEventMouse:
mouse = event.position
if event is InputEventMouseButton and event.pressed:
if event.button_index == MOUSE_BUTTON_LEFT:
var worldspace = player.camera_3d.get_world_3d().direct_space_state
var start = player.camera_3d.project_ray_origin(mouse)
var end = player.camera_3d.project_position(mouse, 1000)
var query = PhysicsRayQueryParameters3D.create(start, end)
var result = worldspace.intersect_ray(query)
Brief setting of my project My character/enemy is a Sprite3D in CharacterBody3D with small collision box only on its feet. I want the mouse to detect the shape of colored pixels of my character/enemy I saw on screen but intersect_ray() always return with collider in the object, so it went through the character to the floor object instead.
Why I don't set the collision box to match the height of sprite? Camera is attached to player with 45 degree angle looking down to the player and it can zoom-in-out and tilt then it will look_at() player again at its new position. While tilting, character's visual is also tilted to parallel with camera. So I think its collision box couldn't be the same size as sprite because sprite's height will be changing all the time and collision box cannot be tilted into the ground too.
visuals.rotation.x = camera_3d.rotation.x
So my question is... Is there a way to do a manual raycasting? or to calculate colored pixels' positions from characters/enemy on screen compare to mouse position and know if it's player or enemy. Please keep in mind that camera can zoom-in or zoom-out and tilting.
Thank you in advance