Загрузка...

How To Make A First Person Controller In Godot

Hello everybody, today I made a first person controller in Godot which as always you can find on my discord at the about section.
Hope you enjoined watching.
Feel free to comment.
Make sure to like, share, and of course subscribe!
See you next time.

This is the code if you don't want it from the discord:
extends CharacterBody3D

@export var speed = 5
@export var jump_velocity = 5
@export var look_sensitivity = 0.01

var gravity = ProjectSettings.get_setting("physics/3d/default_gravity")

@onready var camera:Camera3D = $Camera3D

func _ready(): Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)

func _physics_process(delta):
var input = Input.get_vector("move_left","move_right","move_forward","move_backward").normalized() * speed

velocity = input.x * global_basis.x + input.y * global_basis.z + Vector3(0, velocity.y, 0)

if is_on_floor():
if Input.is_action_just_pressed("jump"): velocity.y = jump_velocity
else: velocity.y -= gravity * delta

move_and_slide()

func _input(event):
if event is InputEventMouseMotion:
rotate_y(event.relative.x * -look_sensitivity)
camera.rotate_x(event.relative.y * -look_sensitivity)
camera.rotation.x = clamp(camera.rotation.x, -PI/2, PI/2)

Видео How To Make A First Person Controller In Godot канала Godot Guru
Яндекс.Метрика

На информационно-развлекательном портале SALDA.WS применяются cookie-файлы. Нажимая кнопку Принять, вы подтверждаете свое согласие на их использование.

Об использовании CookiesПринять