Can't get controls to work in 3D point and click game

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Ertain

I have taken the 3D Navmesh demo (for a point and click game) and have tried adapting it to my needs. While this did work nicely with my setup (in pointing to a place on the map, clicking, and moving the node), I needed some form of collision detection so that the player node knows where not to go. I do not want to run Area checks on all the meshes for which I need detection, so I’ve tried to get point and click controls working with a KinematicBody.

After a suggestion from KidsCanCode in using one of his code recipes, I have cobbled together something which may work.

The node tree for my setup looks something like this:

Scene tree

The “Main” node is a Navigation node, all of the nodes under the “Terrain” node are meshes, and the “Qbit” node is a KinematicBody node. I’m trying to move “Qbit” around inside the NavigationMeshInstance. When I click to move the node, “Qbit” only moves once, and doesn’t move again. I’m not entirely certain, but I think it has something to do with detecting how far the node has moved.

Here’s the code I have on the “Qbit” node:

extends KinematicBody

const SPEED = 3.0
var index: int = 0
var velocity: Vector3 = Vector3()

# For pathfinding
var path
var MainPath
var beginning: Vector3
var ending: Vector3

func _ready():
    MainPath = get_node("/root/Main")

func _physics_process(delta):
    if !path:
        set_physics_process(false)
        return
    var target = path[index]
    var distance = translation.distance_to(target)
    if distance <= 2:
        index = wrapi( index + 1, 0, path.size() )
        target = path[index]
    velocity = (target - translation).normalized() * SPEED
    velocity = move_and_slide(velocity)

func _update_path():
    var temp_path = MainPath.get_simple_path(beginning, ending, true)
    path = Array(temp_path)
    set_physics_process(true)

func _input(event):
    # This fires when the player clicks the left mouse button.
    if event is InputEventMouseButton and event.button_index == BUTTON_LEFT and event.pressed:
        var from = $"../Camera Base/Camera".project_ray_origin(event.position)
        var to = from + $"../Camera Base/Camera".project_ray_normal(event.position)*100
        var p = MainPath.get_closest_point_to_segment( from, to )
        
        beginning = MainPath.get_closest_point( self.get_translation() )
        ending = p
        _update_path()

And just to give some perspective, here’s a screenshot of the game:

Qbit in Squaresville

It looks like the problem came from the player character’s bounding box being too large. Though this has really helped my progress in implementing point and click controls, I’ll still don’t have exactly what I want.

Ertain | 2019-06-07 20:52