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