I simply do not understand where to put my movement code, is it in _process(), in _physics_process()? But how does it get triggered? I can't put a function to recognise that the screen has been clicked into the process function but I also can't call the process function in my click event. I cannot find any straightforward answer to what I thought was very simple code. AI doesn't know the answer either, it just wants to overwrite my input which makes no sense.
Yes, I'm a beginner and yes I should read more documentation, but I cannot find documentation for where to put what.

Here's the code:

extends KinematicBody

export var move_tank := 0.0
export var rot_tank := 0.0

const MOVE_SPEED := 2.0
const ROT_SPEED := 2.0
const MIN_MOVE := -2.0
const MAX_MOVE := 4.0
const MIN_ROT := -90.0
const MAX_ROT := 90.0

var target_move := 0.0
var target_rot := 0.0

# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
	target_move = move_tank
	target_rot = rot_tank

	# Limit target_move and target_rot within the defined range
	target_move = clamp(target_move, MIN_MOVE, MAX_MOVE)
	target_rot = clamp(target_rot, MIN_ROT, MAX_ROT)

	# Move the tank towards the target position
	if target_move != 0:
		var move_dir = Vector3(0, 0, target_move) 
		move_and_collide(move_dir * MOVE_SPEED * delta)

	# Rotate the tank towards the target rotation
	if target_rot != 0:
		var rot_amount = target_rot * ROT_SPEED * delta
		rotate_y(deg2rad(rot_amount * -1))
	
func _input(event: InputEvent) -> void:
	if event is InputEventMouseButton and event.pressed:
		pass #what goes in here that triggers the movement to happen? If I put the whole thing here, I can't use delta

What do I put in pass that triggers the movement code, or where do I put the movement code that doesn't tell me "delta is not defined in the current scope"?

PS: basically all I want is to input a movement and rotation from the inspector, later on to be replaced by canvas UI textfield and button. The tank then moves the input amount, rotates the input amount and done. But actually moves and rotates and doesn't just skip like with translate_object_local. Please help

    https://docs.godotengine.org/en/stable/classes/class_node.html#class-node-method-process
    https://docs.godotengine.org/en/stable/classes/class_node.html#class-node-method-physics-process

    func _process(delta: float) -> void: happen every idle frame 1/60 = 16.666 milliseconds.

    func _physics_process(delta: float) -> void: also every frame but more stable, fixed to FPS of player.

    You want the _physics_process for anything related to movements or anything that directly change (so for sure apply to your tank movement).

    If you using Godot 4.1.1 and try to attach a new script to a CharacterBody3D or CharacterBody2D you will get a default script with some basic instruction and helps that will show you how movements works.
    You will see that movements are store in func _physics_process and every move is active every frame, it just need an input.

    https://docs.godotengine.org/en/stable/tutorials/scripting/creating_script_templates.html#creating-script-templates

      fatalox func _process(delta: float) -> void: happen every single frame 1/60 = 16.666 milliseconds.

      _process runs in every idle frame. It can run much more frequently than 60 times per second.

        DaveTheCoder I see but in every idle frame not below 16.666 milliseconds i believe, right?

        the frequency does not matter that much.
        what do you expect to do with the movement? that's what matters.
        physics_process provides a constant frequency.
        while _process will only update before rendering.
        _input (or other input process functions) for functions that you need executed on inputs.

        use _unhandled_input + get_viewport().set_input_as_handled() to set a local variable.
        use _physics_process to use that local variable to apply physics.
        use _process to update camera position bc it's used for rendering.
        and while it's not recommended, networking functions are usually put in _process. i think this is not good but that's how it's done for now.
        / func _unhandled_input(event):
        / if event.is_action("character_up"):
        / if event.is_pressed():
        / // set variable.
        / get_viewport().set_input_as_handled()

        stupid spaces don't work in this text editor but the last line has an indent to run only if action is "character_up"

        func _unhandled_input(event):
            if event.is_action("character_up"):
                if event.is_pressed():
                    # set variable.
                    get_viewport().set_input_as_handled()

        See here, under the section Multiline code blocks.

        esfasdgasdfasd So I found out, there's alot of other stuff wrong with this code, but the Answer to my Question would have been to pass a variable.

        func _input(event: InputEvent) -> void:
        	if event is InputEventMouseButton and event.pressed:
        		is_moving = true #here, added this and then
        
        func _process(delta: float) -> void:
        	target_move = move_tank
        	target_rot = rot_tank
        
        	# Limit target_move and target_rot within the defined range
        	target_move = clamp(target_move, MIN_MOVE, MAX_MOVE)
        	target_rot = clamp(target_rot, MIN_ROT, MAX_ROT)
        
        	# Move the tank towards the target position
        	if is_moving: #pass it to here!!!
        		if target_move != 0:
        			var move_dir = Vector3(0, 0, target_move) 
        			move_and_collide(move_dir * MOVE_SPEED * delta)

        That's all I needed for this present problem, although I'm not sure if it's the correct/inteded way.

        esfasdgasdfasd changed the title to I don't understand what is wrong (Update, I do) .