Godot Version
4.6.1
Question
M trying to rotate the Characterbody3d when i press WASD but it rotates with camera y axis rotation ?
Script :
extends Node3D
var camera_rotation : Vector2 = Vector2.ZERO
var mouse_sens : float = 0.001
var max_y : float = deg_to_rad(80)
@export var character : CharacterBody3D
func _ready() :
Input.mouse_mode = Input.MOUSE_MODE_CAPTURED
func _input(event) :
if Input.is_action_just_pressed("escape"):
if Input.get_mouse_mode() == Input.MOUSE_MODE_CAPTURED:
Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE)
else :
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
if event is InputEventMouseMotion :
var mouse_event : Vector2 = event.screen_relative * mouse_sens
camera_look(mouse_event)
func camera_look (mouse_movement : Vector2) -> void :
camera_rotation += mouse_movement
transform.basis = Basis()
character.transform.basis = Basis()
character.rotate_object_local(Vector3(0,1,0) , -camera_rotation.x)
rotate_object_local(Vector3(1,0,0) , -camera_rotation.y)
camera_rotation.y = clamp(camera_rotation.y, -max_y , max_y)
All i know is its because of line 30 in the script ; character.rotate_object_local(Vector3(0,1,0) , -camera_rotation.x)