Godot Version
Godot 4.5
Question
I’ve recently been trying to implement a Resident Evil/Parasite Eve-esque/etc. style fixed camera system. I’ve looked at a few videos covering how to code this and have gotten it to work in theory, but I’ve been having an issue where WASD movement works incorrectly, where going left, right, forward and backward does not change relative to where the camera is to the player, and I’m having a harder time figuring this one out. I managed to do this for a rotating 3rd-person camera through some tutorials I did awhile ago, which I did understand relatively well, but when trying to apply the same code to these static cameras, it does not work. Below includes 1.) Player character movement script, 2.) What I tried in order to fix the movement inconsistency, and 3.) The script attached the fixed cameras’ Area3D’s (which allows the functionality to change from one camera to another.) in case.
#region movement vectors
var motion := Input.get_vector("right","left","backward","forward")#.rotated(-camera.global_rotation.y)
var direction = (camera.global_transform.basis * Vector3(motion.x, 0, motion.y)).normalized()
direction = Vector3(direction.x, 0, direction.z).normalized() * motion.length()
if direction:
velocity.x = direction.x * base_speed
velocity.z = direction.z * base_speed
else:
velocity.x = move_toward(velocity.x, 0, base_speed)
velocity.z = move_toward(velocity.z, 0, base_speed)
#endregion
#previous code used in order to make movement relative to where the camera was facing for a moveable 3rd person camera
extends Camera3D
class_name StaticCameraController
@export var min_limit_x: float
@export var max_limit_x: float
@export var vertical_acceleration := 1.0
@export var horizontal_acceleration := 2.0
func _process(delta: float) -> void:
var movement = Input.get_vector("left_button", "right_button", "up_button", "down_button")
rotate_from_vector(movement * delta * Vector2(horizontal_acceleration, vertical_acceleration))
func rotate_from_vector(v: Vector2):
if v.length() == 0: return
rotation.y -= v.x
rotation.x += v.y
rotation.x = clamp(rotation.x, min_limit_x, max_limit_x)
#resident evil/fixed camera angle script
extends Area3D
class_name CameraSceneController
@onready var default_camera = $"."
@onready var camera = get_parent()
@onready var cam3d = Camera3D
var in_trigger = false
func enter_trigger(body):
if body.name == "Player":
in_trigger = true
func exit_trigger(body):
if body.name == "Player":
in_trigger = false
func _process(_delta: float) -> void:
#print(in_trigger)
for body in get_overlapping_bodies():
if body is Player:
in_trigger = true
camera.current = true