P.S i am sorry it send accidentally while i am still writing, here is the full discussion
Greeting mate, I am working on a RTS camera script. I learned that i have to raycast from camera in order to project the mouse position to an collision shape. I made the casting successfully, however, I cannot print out the position element that is returned from dictionary.
Here is my code
if (Input.IsActionJustPressed("Move")) {
MousePos = GetViewport().GetMousePosition();
Vector3 startPt = viewPlane.ProjectRayOrigin(MousePos);
Vector3 endPt = startPt + viewPlane.ProjectRayNormal(MousePos) * rayLength;
var state = GetWorld().DirectSpaceState;
var result = state.IntersectRay(startPt, endPt);
GD.Print(result); // I can print this one, the whole dictionary
if (result.Contains("Position")&&result.Count!=0)
{
GD.Print(result.Get["position"]); // I can never print this even if result is exist
}
}
In this code, i can print out the whole "result", which is the whole dictionary with no problem, however, i can't print the
"position" element in result, which indeed exist in the result. Unfortunately, it is what godot doc told to extract the element,
do you guys have clues, thank you
Here is the output if i print out the whole "result"
{collider:[RigidBody:1240], collider_id:1240, normal:(0, 1, -0), position:(1.094041, 1.000003, 0.587834), rid:[RID], shape:0}
which have a positino element indeed, however, i can't print out the element alone with the guidance provided by documents
godot doc on raycasting
https://docs.godotengine.org/en/stable/tutorials/physics/ray-casting.html