FPS Character Controller - Weapons not rotating with camera

Godot Version

4.1.3 Stable


When running the scene, my character’s weapon doesn’t move with the camera. It’s as if it’s on a delay and the change in position is halved from the rotational position of the head/camera. Here’s some snippets of my Player script.

Variables + Camera mouse movement.

var weapon_to_spawn
var weapon_to_drop

@onready var reach = $Head/Camera3D/Reach
@onready var hand = $Head/Hand

@onready var sword_equipped = load("res://Main/Sword_Equipped.tscn")
@onready var sword_on_ground = load("res://Main/sword_on_ground.tscn")

func _ready():
	Input.mouse_mode = Input.MOUSE_MODE_CAPTURED

func _input(event):
	if event is InputEventMouseMotion and Input.mouse_mode == Input.MOUSE_MODE_CAPTURED:
		rotate_y(deg_to_rad(-event.relative.x * mouse_sensitivity))
		$Head.rotate_x(deg_to_rad(-event.relative.y * mouse_sensitivity))
		$Head.rotation.x = clampf($Head/Camera3D.rotation.x, -deg_to_rad(70), deg_to_rad(70))
	if event.is_action_pressed("ui_cancel"):
		Input.mouse_mode = Input.MOUSE_MODE_VISIBLE
	if event.is_action_pressed("click"):
		if Input.mouse_mode == Input.MOUSE_MODE_VISIBLE:
			Input.mouse_mode = Input.MOUSE_MODE_CAPTURED

Equipping items.

func _process(delta):
	if reach.is_colliding():
		if reach.get_collider().get_name() == "Sword_On_Ground":
			weapon_to_spawn = sword_equipped
			weapon_to_spawn = null
		weapon_to_spawn = null
	if hand.get_child(0) != null:	
		if hand.get_child(0).get_name() == null:
			weapon_to_drop = null
		elif hand.get_child(0).get_name() == "sword_equipped":
			weapon_to_drop = sword_on_ground.instance()
	if Input.is_action_just_pressed("Interact"):
		print("interact pressed")
		if weapon_to_spawn != null:
			if hand.get_child(0) != null:
				weapon_to_drop.global_transform = hand.global_transform
				weapon_to_drop.dropped = true
			get_node(weapon_to_spawn).rotation = get_node(hand).rotation

And my player scene node tree.

What could be the issue? I’m still pretty new to Godot, any advice is welcome!

Here’s a gif of the scene.

You got to put the hand as child of the camera because you are rotating the camera and not the head, try it and let me know how it goes

I made the hand a child of Camera3D and changed it’s path in the code.

It still moves separately from the camera, now it rotates separately as well. I’ll try to add a gif to show what it looks like.

I don’t understand why
What about turning head node? Have you tried that?
I think I remember something similar happened to me once but I deleted that feature.

It’s not ideal but you can set
camera rotation = hand rotation in _process(delta) function.

It think it was something like this. Not sure.

Just in case
Maybe its because of rigid body?
Can you try another node? Like static body? Just test it I’m curious

Changing Sword_Equipped from a RigidBody3D to StaticBody3D worked! Thank you!

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.