Based on the action it seems like your $head or $head/Camera3D node is offset, make sure they are centered with the player by resetting any transform/position on both nodes.
that is. I thought you meant you were going to move it the camera whenever you said this.
thanks
did that fix the issue?
no, i didnāt
i moved part of script to the node3d which contains camera, and logically i thought it should help
can you give me your controller? if they are similar i want to look
It differs from yours in function slightly, and I removed the functions that are completely unrelated to movement and the camera, but here you go. the equivalent of $neck in my code is your $head I believe
extends CharacterBody3D
@export var camSensitivity = .01;
var stamina = 100.0
signal stamina_report(stamina)
var SPEED = 7.5
const JUMP_VELOCITY = 3.0
const crouch_speed = 4.0
const default_speed = 7.5
const sprint_speed= default_speed * 1.5
var def_height = 1.5
var crouch_height = 1
var can_control := true
var reported = 2
signal report_to_shader(value, tolerance)
signal report_to_vignette(damage_type, health)
var timer_for_temp_damage : Timer = null
var timer_for_regen : Timer = null
@export var base_health_regen_time = 6.0
var health_regen_time = base_health_regen_time
#some variables handling vaulting
var can_jump := true
var camera_can_move := true
var is_crouching :=false
func can_vault():
if (!$Neck/raycasts/chestcast.is_colliding()):
return false
for ray in $Neck/raycasts/headcasts.get_children():
if (ray.is_colliding()):
return false
if(stamina < 20):
return false
return true
func vault():
can_jump = false
camera_can_move = false
var v_move_time := .2
var h_move_time := .1
if !is_crouching:
var vertical_movement = global_transform.origin + Vector3(0, 1.5 ,0)
var vm_tween = get_tree().create_tween().set_trans(Tween.TRANS_CUBIC).set_ease(Tween.EASE_IN)
var cam_tween = get_tree().create_tween().set_trans(Tween.TRANS_CUBIC).set_ease(Tween.EASE_IN)
vm_tween.tween_property(self, "global_transform:origin", vertical_movement, v_move_time)
cam_tween.tween_property(cam, "rotation_degrees:x", clamp(cam.rotation.x - deg_to_rad(-30), deg_to_rad(60), 90), v_move_time)
cam_tween.tween_property(cam, "rotation_degrees:z", (-5.0*sign(randf_range(-10000,10000))), v_move_time)
cam.add_trauma(.5)
await vm_tween.finished
var forward_movement = global_transform.origin + Vector3(-neck.basis.z)
var fm_tween = get_tree().create_tween().set_trans(Tween.TRANS_LINEAR)
var cam_reset = get_tree().create_tween().set_trans(Tween.TRANS_CUBIC).set_ease(Tween.EASE_IN)
fm_tween.tween_property(self, "global_transform:origin", forward_movement, h_move_time)
cam_reset.tween_property(cam, "rotation_degrees:x", 0.0, h_move_time)
cam_reset.tween_property(cam, "rotation_degrees:z", 0.0, h_move_time)
can_jump= true
camera_can_move = true
var gravity = ProjectSettings.get_setting("physics/3d/default_gravity")
@onready var neck := $Neck
@onready var cam := $Neck/shakeable_camera
@onready var pcap = $CollisionShape3D
#handles the raw input from the mouse and translates it to movement on the neck and camera
func _unhandled_input(event: InputEvent) -> void:
if event is InputEventMouseButton and camera_can_move and not get_tree().paused:
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
elif event.is_action_pressed("ui_cancel") or get_tree().paused:
Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE)
if Input.get_mouse_mode() == Input.MOUSE_MODE_CAPTURED:
if event is InputEventMouseMotion:
neck.rotate_y(-event.relative.x * camSensitivity)
cam.rotate_x(-event.relative.y * camSensitivity)
#limits the amount the player can rotate head left or right, may need to be tweaked in future
cam.rotation.x = clamp(cam.rotation.x, -PI/3, PI/3)
func _physics_process(delta):
SPEED = default_speed
is_crouching = false
pcap.shape.height = clamp(pcap.shape.height, crouch_height, def_height)
cam.position.y = clamp(cam.position.y, crouch_height, def_height)
stamina = clamp (stamina, 0.0, 100.0)
if(can_control):
if(Input.is_action_pressed("crouch")):
stamina += 10 * delta
if not is_on_floor() and !can_vault():
velocity.y -= gravity * delta
stamina -= 15 * delta
# Handle jump.
if Input.is_action_pressed("ui_accept") and can_vault() and is_on_floor():
stamina -= 300 * delta
vault()
elif Input.is_action_just_pressed("ui_accept") and is_on_floor() and can_jump:
velocity.y = JUMP_VELOCITY
if Input.is_action_pressed("crouch"):
pcap.shape.height -= 3 * delta
cam.position.y -= 3 * delta
else:
pcap.shape.height += 3 * delta
cam.position.y += 3 * delta
# Get the input direction and handle the movement/deceleration.
# As good practice, you should replace UI actions with custom gameplay actions.
var input_dir = Input.get_vector("left", "right", "up", "down")
#Uses Neck orentation instead of player orentation
var direction = (neck.transform.basis * Vector3(input_dir.x, 0, input_dir.y)).normalized()
if direction:
if (Input.is_action_pressed("sprint") and not Input.is_action_pressed("crouch") and is_on_floor()):
stamina -= 30 * delta
if(stamina >= .1):
SPEED = sprint_speed
elif(Input.is_action_pressed("crouch")):
SPEED = crouch_speed
is_crouching = true
else:
SPEED = default_speed
velocity.x = direction.x * SPEED
velocity.z = direction.z * SPEED
else:
SPEED = default_speed
velocity.x = direction.x * SPEED
velocity.z = direction.z * SPEED
stamina += 15 * delta
move_and_slide()
stamina_report.emit(stamina)
and i think maybe guy in the guide somehow fixed that issue and i have to look closely
maybe this is because of shitty camera position
I believe that is what GertKeno suggested above. Heās really experienced and has consistently provided the best advice on this forum in my experience.
i think iāve figured out, itās because i donāt used āheadā node, which should fix view in one position
and itās completely chaos in my main scene
In your originally provided code you were rotating the head along the x axis, but not the y axis
yes, typically is better to pack your character into its own scene, but it shouldnāt directly contribute to this issue
i think i should try another controller method
Iām not sure that is strictly necessary. Can you send any edits that youāve made to your character controller script since youāve opened this post? I will try to copy them on my computer and bug test for you.
i canāt
itās too confusing
I mean just copy and paste it
extends Node3D
const sens = 0.1
@onready var head = $head
func _input(event):
if event is InputEventMouseMotion:
rotate_y(deg_to_rad(-event.relative.x * sens))
head.rotate_x(deg_to_rad(-event.relative.y * sens))
head.rotation.x = clamp(head.rotation.x, deg_to_rad(-90), deg_to_rad(90))
extends Node3D
const sens = 0.1
@onready var head = $head
func _input(event):
if event is InputEventMouseMotion:
$head/Camera3d.rotate_y(-event.relative.x * sens) head.rotate_x(deg_to_rad(-event.relative.y * sens))
head.rotation.x = clamp(head.rotation.x, deg_to_rad(-90), deg_to_rad(90))