Godot 4.2
Hi all! I started learning how to game make with godot about 2/3 weeks ago, with very little experience (I made a few Flash games about 15 years ago) and I’m trying to come to terms with everything new.
I’m trying to make a survival horror, along the lines of original RE and Silent Hill, so fixed camera angles - however, I’ve reached an issue where my character will control fine, but if I cut to a camera angle that is facing the front of the character my brain obviously goes, I need to push up on the controller to go back through the door I entered, but in the game world, that’s actually back - and it’s causing a bit of a struggle for me to make that connection in my head.
So i’m trying to find out/figure out how to do camera relative movement, in a fixed angle camera setting and i’m having 0 luck, I can find loads for Unity, but none for Godot
I know I need to code my character to respond to whatever Camera3D is active, but I don’t know how to do that and I don’t know how to make my controls relative to that. If anyone can give me some help, I’d really appreciate it.
Please see my current code, below
extends CharacterBody3D
var SPEED = 3.0
var walking_speed = 3.0
var running_speed = 4.75
@onready var animation_player = $Visuals/mixamo_base/AnimationPlayer
@onready var visuals = $Visuals
var walking = false
var running = false
func _physics_process(delta: float) -> void:
if Input.is_action_pressed("sprint"):
SPEED = running_speed
running = true
animation_player.play("running")
else:
SPEED = walking_speed
running = false
if Input.is_action_just_released("sprint"):
animation_player.play("walking")
# Get the input direction and handle the movement/deceleration.
var input_dir := Input.get_vector("left", "right", "forward", "backwards")
var direction := (transform.basis * Vector3(input_dir.x, 0, input_dir.y)).normalized()
if direction:
velocity.x = direction.x * SPEED
velocity.z = direction.z * SPEED
visuals. look_at(direction + position)
if !walking:
walking = true
animation_player.play("walking")
else:
velocity.x = move_toward(velocity.x, 0, SPEED)
velocity.z = move_toward(velocity.z, 0, SPEED)
if walking:
walking = false
animation_player.play("idle")
move_and_slide()