#Getting which cell is clicked in a gridmap

1 messages · Page 1 of 1 (latest)

brazen pecan
#

I have a gridmap with voxels and they have static bodies and colliders, I'm trying to cast a intersect array to get the instance of the cube, and to later put something in the gridmap relative to the block, currently stuck at getting the thing clicked on this is my code:

public override void _PhysicsProcess(double delta)
{
    Vector2 mousePosition = GetViewport().GetMousePosition();

    Camera3D camera = GetViewport().GetCamera3D();
    Vector3 rayFrom = camera.ProjectRayOrigin(mousePosition);
    Vector3 rayTo = rayFrom + camera.ProjectRayNormal(mousePosition) * 1000;

    PhysicsDirectSpaceState3D spaceState = GetWorld3D().DirectSpaceState;
    Godot.Collections.Dictionary result = spaceState.IntersectRay(PhysicsRayQueryParameters3D.Create(rayFrom, rayTo));

    if (result.Count > 0)
    {
        //No clue what to do here
    }
}
elfin bison
#

Per the documentation, you get a dictionary back that has a "collider" entry, which is the object that has been hit. From there you can get the position of the object and do your thing.
https://docs.godotengine.org/en/stable/tutorials/physics/ray-casting.html

brazen pecan
#

Either im dumb or it has to actual examples of casting the collider to the actual object

#

thats where im stuck at

#

as keyword doesnt work

elfin bison
#

You should be able to access it with something like result["collider"]

brazen pecan
#

Yea i am but im pretty sure i have to cast it to what it is to interact with it but i cant