i was looking stuff to learn godot and this video pop up in my recommends, nice work on the explanation, keeping it simple while teaching a bit. thank you!
@smokysmoky34512 ай бұрын
i like it
@yeazye6 күн бұрын
extends CharacterBody3D @export var MoveSpeed: float = 5.0 @export var JumpPower: float = 4.5 @export var Sensitivity: float = 0.005 @onready var head: Node3D = $Head func _ready() -> void: Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED) func _input(event: InputEvent) -> void: # Rotate the character with mouse motion if event is InputEventMouseMotion: rotate_y(-event.relative.x * Sensitivity) # Rotate head and clamp its rotation to prevent over-rotation var new_head_rotation_x = head.rotation_degrees.x - event.relative.y * Sensitivity * 180 / PI new_head_rotation_x = clamp(new_head_rotation_x, -90, 90) # Clamping rotation head.rotation_degrees.x = new_head_rotation_x func _physics_process(delta: float) -> void: # Apply gravity if not is_on_floor(): velocity.y -= float(ProjectSettings.get_setting("physics/3d/default_gravity")) * delta # Handle jumping if Input.is_action_just_pressed("jump") and is_on_floor(): velocity.y = JumpPower # Process movement process_move(delta) func process_move(delta: float) -> void: var input_dir = Input.get_vector("move_left", "move_right", "move_forward", "move_backward") var direction = (global_transform.basis * Vector3(input_dir.x, 0, input_dir.y)).normalized() if direction.length() > 0: velocity.x = direction.x * MoveSpeed velocity.z = direction.z * MoveSpeed else: velocity.x = lerp(velocity.x, 0.0, 0.1) velocity.z = lerp(velocity.z, 0.0, 0.1) # Move and slide using velocity move_and_slide()