Currently the code setup I have for my camera is based on a node rotating both on the y axis and x axis. Unfortunately the way I set up my character's movement relative to the camera has the character slowing down on the x axis with the rotation of the camera
extends CharacterBody3D
var gravity = 14
var Player = {
“level”: 1,
“experience”: 0,
“health” :10,
“mp” : 1,
“strength”: 1,
“def” : 1,
“ap”: 1,
“jump_height”: 400,
“speed”: 5
}
func _physics_process(delta): #Shmoving
var input_dir = Input.get_vector(“move_left”, “move_right”, “move_up”, “move_down”)
var direction = ($Pivot.transform.basis * Vector3(input_dir.x,0,input_dir.y)).normalized()
if direction:
velocity.x = direction.x * Player.speed
print(velocity.x)
velocity.z = direction.z * Player.speed
print(velocity.z)
else:
velocity.x = 0
velocity.z = 0
#JUMPING BEAN
if Input.is_action_pressed("jump") and is_on_floor():
if velocity.z > 0 or velocity.x > 0:
velocity.y = Player.jump_height * delta
else:
velocity.y = Player.jump_height * delta
#Face direction
if input_dir != Vector2(0,0):
$Sprite3D.rotation_degrees.y = $Pivot.rotation_degrees.y - rad_to_deg(input_dir.angle()) + 90
#CRASHING BEAN SORA
if not is_on_floor():
velocity.y -= gravity * delta
move_and_slide()
I’m hoping someone else has a better solution to this
I don’t really understand what is the problem you’re having and what’s your expectation? Could you clarify? Ideally with a short video of the behavior.
Please paste your code as preformatted text with triple backticks ``` at the beginning and end of the code snippet.
This piece of movement code uses the pivoting node for the camera to move in the direction the camera faces so forward is relative to the camera, which causes a problem when the camera faces either down or up and the camera’s “forward” leans into the floor, slowing the movement speed.
( I tried uploading a video of the issue but I’m a new user)
tldr; the forward movement speed drops when the camera faces down or up cuz the forward is based on pivot angle
Typically others rotate the character node around the Y axis and the camera node around the X axis, this separation allows the character’s basis to remain parallel to the floor, so using basis * Vector3(input_dir.x,0,input_dir.y) results in a planar movement relative to the character’s facing direction.