Godot Version
4.6.2
Question
I’ve been looking through this forum to see if I could apply anyone else’s solutions to having it so that when the direction of the camera changes, left, right, up and down are applied correctly so that they move relative to where the camera is facing. I notice its a pretty common issue people get, so I apologize for making another post asking about this when it’s probably been done many times. I seem to have a unique problem however; I’m using tweens to change the orientation of the camera. I’m not sure if this is the best solution for the effect I’m trying to do, but its what I started with, and am unsure how to modify it. The tween moves the transform of the player which moves the camera_3d child.
One thing I should mention: Before making finally this post, I decided to try and use linear interpolation to remake the system I had with tweens and instead rotate the camera to a certain position, which did in some ways, work (I might have to check for the Area3D without signals now?) With my current system of organization, I am still unsure how to change the global direction though after the camera is rotated.
Anyways though, these are all the scripts that are used for movement and cameras:
class_name Player extends CharacterBody3D
@onready var input_component: InputComponent = %InputComponent
@onready var movement_component: MovementComponent = %MovementComponent
@onready var climbing: Climbing = %Climbing
@onready var camera_3d: Camera3D = $Camera3D
var tween: Tween
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _physics_process(delta: float) -> void:
input_component.update()
movement_component.direction = input_component.move_dir
movement_component.jump_counter = input_component.jump_pressed
movement_component.tick(delta)
climbing._climbing(delta)
#camera_3d.transform = camera_3d.transform.interpolate_with($position2.transform, 1.0)
func _on_area_3d_body_entered(body: Node3D) -> void:
#tween = create_tween()
#tween.tween_property(self,"global_transform:basis", global_transform.basis.rotated(Vector3.UP, PI/2),0.5)
pass
func _on_area_3d_2_body_entered(body: Node3D) -> void:
tween = create_tween()
tween.tween_property(self,"transform:basis", global_transform.basis.rotated(Vector3.UP, -PI/2),0.5)
I decided to keep some tags and examples of what I tried. The signal is the system I used before trying to use linear interpolation. The interpolation I tried applying to the signal is tagged in physics_process at the bottom.
class_name InputComponent extends Node
var jump_pressed : bool = false
var move_dir := Vector2.ZERO
@onready var camera_3d: Camera3D = $"../Camera3D"
func update() -> void:
move_dir = Input.get_vector("up", "down", "right", "left")
jump_pressed = Input.is_action_just_pressed("jump")
Currently when trying to do change the global direction of the player, I am aware I keep getting an error due to me trying to apply Vector3 to Vector2 ? I know what the error means, but I’m unsure how to improvise.
class_name MovementComponent extends Node
@onready var body : CharacterBody3D = get_parent()
@onready var input_component: InputComponent = %InputComponent
@onready var camera: Camera3D = $"../Camera3D"
#variables for movement and physics
const RUN_SPEED : float = 30.0
const SPEED : float = 20.0
@export var current_speed : float = SPEED
@export var jump_velocity : float = 12.0
@export var gravity_multiplier : float = 3.0
@onready var climb_ray: RayCast3D = $"../ClimbRay"
var direction: Vector2 = Vector2.ZERO
var jump_counter := false
func tick(delta: float) -> void:
#Move
body.velocity.x = direction.x*current_speed
body.velocity.z = direction.y*current_speed
#Gravity
if not body.is_on_floor():
body.velocity += body.get_gravity() * delta * gravity_multiplier
#Jump
if jump_counter and body.is_on_floor():
body.velocity.y = jump_velocity
jump_counter = false
body.move_and_slide()
This is all.


