what is the Problem in this code?

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

i wachted an Youtube tutorial and this 3d movement script should work. The Camera movent does work but the player movement dosent work.

extends KinematicBody

export var speed := 7.0
export var jump_strength:= 20.0
export var gravity := 50.0

var _velocity := Vector3.ZERO 
var _snap_vector := Vector3.DOWN

onready var _spring_arm: SpringArm = $SpringArm
onready var _model: Spatial = $MeshInstance

func _physics_process(delta: float) -> void:
var move_direction := Vector3.ZERO
move_direction.x = Input.is_action_pressed ("right")
move_direction.y = Input.get_action_strength("back") - Input.get_action_strength("forward")
move_direction = move_direction.rotated(Vector3.UP, _spring_arm.rotation.y).normalized()


_velocity.x = move_direction.x * speed
_velocity.z = move_direction.z * speed
_velocity.y -= gravity * delta

var just_landed := is_on_floor() and _snap_vector == Vector3.ZERO
var is_jumping := is_on_floor() and Input.is_action_just_pressed("jump")
if is_jumping:
	_velocity.y = jump_strength
	_snap_vector = Vector3.ZERO
elif just_landed:
	_snap_vector = Vector3.DOWN
_velocity = move_and_slide_with_snap(_velocity, _snap_vector, Vector3.UP, true)


if _velocity.length() > 0.2:
	var look_direction = Vector2(_velocity.z, _velocity.x)
	_model.rotation.y = look_direction.angle()
	


func _process(_delta: float) -> void:
_spring_arm.translation = translation

Spring Arm Script:

extends Spatial

export var mouse_sensitivity := 0.05

func _ready() -> void:
set_as_toplevel(true)
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)

func _unhandled_input(event: InputEvent) -> void:
if event is InputEventMouseMotion:
	rotation_degrees.x -= event.relative.y * mouse_sensitivity
	rotation_degrees.x = clamp(rotation_degrees.x, -90.0,  30.0)
	
	rotation_degrees.y -= event.relative.x * mouse_sensitivity
	rotation_degrees.y = wrapf(rotation_degrees.y, 0.0,  360.0)

In what way doesn’t it work?

SteveSmith | 2022-10-20 08:18