Godot Version
4.4
Question
Hello,
I followed Brackeys 3D godot tutorial and am trying to edit the character controller so that it just lets me be in free camera automatically. My problem is that when I place the cameraman in the scene and specify its starting rotation in the inspector it flips back to its “default” position once the mouse moves. Bellow is what I’ve edited the code down to and I would love any information on what’s happening and why its doing this and how I can fix it/ resources I should be looking at. I think it has something to do with the basis and transform but I’m unsure how I would fix it. Thank you!
Here’s the node hierarchy as well:
var mouse_captured : bool = false
var look_rotation : Vector2
var move_speed : float = 10.0
var look_speed : float = .002
var cameraInputDirection:= Vector2.ZERO
func _ready() -> void:
velocity = Vector3.ZERO
func _physics_process(delta: float) -> void:
var input_dir := Input.get_vector("left","right","up","down")
var input2 := Input.get_axis("ctrlDOWN","spaceUP")
var motion := (head.global_basis * Vector3(input_dir.x , 0 + input2, input_dir.y)).normalized()
motion *= move_speed * delta
move_and_collide(motion)
#print(transform)
func _unhandled_input(event: InputEvent) -> void:
if Input.is_mouse_button_pressed(MOUSE_BUTTON_LEFT):
capture_mouse()
if Input.is_key_pressed(KEY_ESCAPE):
release_mouse()
# Look around
if mouse_captured and event is InputEventMouseMotion:
rotate_look(event.relative)
# Rotate us to look around.
# Base of controller rotates around y (left/right). Head rotates around x (up/down).
# Modifies look_rotation based on rot_input, then resets basis and rotates by look_rotation.
func rotate_look(rot_input : Vector2):
look_rotation.x -= rot_input.y * look_speed
look_rotation.x = clamp(look_rotation.x, deg_to_rad(-85), deg_to_rad(85))
look_rotation.y -= rot_input.x * look_speed
rotate_y(look_rotation.y)
head.transform.basis = Basis()
head.rotate_x(look_rotation.x)
print(Me.global_rotation)
func capture_mouse():
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
mouse_captured = true
func release_mouse():
Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE)
mouse_captured = false