<s>[INST] How can you write a first person controller script in GDscript and apply it to a KinematicBody-node when using Godot Engine 3.x and what is the equivalent to the KinematicBody-node in Godot Engine 4.x and how does the first person controller script need to be changed to work in Godot Engine 4.x? [/INST] You may wish to create a node to poll all control inputs and store them in publicly accessible variables or arrays. Create references to these input events that trigger the animation functions.</s>\ <s>[INST] Can you please provide some detailed instruction as to how to accomplish this? [/INST] Here is an example of a first person controller script in GDScript for Godot Engine 3.x and how it can be applied to a KinematicBody node:


extends KinematicBody

var velocity = Vector3()
var speed = 10

func _physics_process(delta):
    velocity = Vector3()

    if Input.is_action_pressed("move_forward"):
        velocity.z -= 1
    if Input.is_action_pressed("move_backward"):
        velocity.z += 1
    if Input.is_action_pressed("move_left"):
        velocity.x -= 1
    if Input.is_action_pressed("move_right"):
        velocity.x += 1

    velocity = velocity.normalized() * speed
    move_and_slide(velocity)

To apply this script to a KinematicBody node in your scene, create a new KinematicBody node, right-click it, and select "Attach Script." Then paste the script into the new script file and save it.

To make this script work in Godot Engine 4.x, the script needs to be updated to use the new API, which includes some syntax changes and changes to how physics are processed. Here is an updated version of the script that should work in Godot Engine 4.x:

extends KinematicBody

var velocity = Vector3.ZERO
var speed = 10

func _physics_process(delta):
    velocity = Vector3.ZERO

    if Input.is_action_pressed("move_forward"):
        velocity.z -= 1
    if Input.is_action_pressed("move_backward"):
        velocity.z += 1
    if Input.is_action_pressed("move_left"):
        velocity.x -= 1
    if Input.is_action_pressed("move_right"):
        velocity.x += 1

    velocity = velocity.normalized() * speed
    move_and_slide(velocity)

Note that in Godot Engine 4.x, the KinematicBody node has been renamed to RigidBody, and the move_and_slide method has been replaced with move.</s>