Ps2 (RE4) character movement

Question

im not a beginner but i dont really know how to make a character third person controller. im using ui_left and ui_right for rotating the camera left or right while the ui_up and ui_down for moving forward or backwards but the problem is that if the camera i rotated the character wont go front but would only go backwards *i mean tha the character goes only front but when the camera i rotated it wont follow the direction so he goes still the same way*

extends CharacterBody3D

@onready var view_y := %view_x
@onready var view_x := $view_y
@onready var body := %body

const SPEED = 5.0
const JUMP_VELOCITY = 4.5
const SPEED2 = 0.05

@onready var sensitivity := 0.01

func _input(event: InputEvent) -> void:
	
	
	
	
	if event is InputEventScreenDrag:
		view_x.rotation.x -= event.relative.y * sensitivity 
		view_y.rotation.y -= event.relative.x * sensitivity #view_y doesent "work" bc we dont need it
		
		view_x.rotation.x = clampf(view_x.rotation.x, deg_to_rad(-60), deg_to_rad(60))
		

		
	
func _physics_process(delta: float) -> void:
	
	if Input.is_action_pressed("ui_right"):
		view_y.rotation.y -= 5 * sensitivity
	
	
	
	
	if Input.is_action_pressed("ui_left"):
		view_y.rotation.y += 5 * sensitivity
		

	
	# Add the gravity.
	if not is_on_floor():
		velocity += get_gravity() * delta

	# Handle jump.
	if Input.is_action_just_pressed("ui_accept") and is_on_floor():
		velocity.y = JUMP_VELOCITY
		
		
		
		
		
	# Get the input direction and handle the movement/deceleration.
	# As good practice, you should replace UI actions with custom gameplay actions.


	move_and_slide()

Check out my Camera3D Plugin. It provides first person and 3rd person camera functionality, as well as the ability to switch between them, and supports mouse/keyboard and gamepads. You can either use it, or learn from it.

I cant reqlly figure out srry :kissing_face:

There are instructions on using it…

Srry i meant with downloading from github bc i dont use it from years so idk how to download the zip instead a file at a time

I did it thanks a lottt ttt!!!

1 Like