My player's collision box is acting weird.

Godot Version

Godot 4

Question

I’m currently making a first person horror game (with flashlight and key/unlocking door mechanics!) and i keep colliding with my walls and doors when im a couple feet away from the wall. I kept turning off the walls and door collisions to see whats wrong, I believe the problem is with my player’s collision box or something. The screenshots are of me colliding with the wall and the distance (besides the 1st one)




Go to the Debug menu and select Visible Collision Shapes. Then play your game again. You’ll be able to see your problem quite easily then.

It worked I found the problem, but im pretty new so I have no idea how to fix it. Turns out I rotate my camera but not the collision shape so the camera will rotate in the collision shape. Ill try to figure it out rn though, thanks!

This might not be a perfect solution as I do not know what your code is or what is parented to what, but, you can try this:


@onready var whatever_name_you_want : CollisionObject3D = $DeleteAddDragCollisionHere

func _process(delta: float) -> void:
	whatever_name_you_want.rotation.y = your_camera_rotation_var.y
	#Makes the collision rotate left/right, if your camera's parent is the collision, it'll be rotated left/right with collision.
	camera_name.rotation.x = your_camera_rotation_var.x
	 #The camera will rotate up/down on it's own, not effecting the collision. You don't want to also rotate it's y (If it's parent is the collision) as it'll be rotated twice.

(This is assuming you’ve attached the script to your player (Rigidbody or CharacterBody) if it’s attached to your camera, change out camera_name.rotation for rotation

Heres a picture of my code and the nodes my player is connected to

try adding this below camera.rotation.x and replace $DragCollisionShape3DHereOrAddVarRef:

$DragCollisionShape3DHereOrAddVarRef.rotation.y = head.rotation.y

or you can just drag the CollisionShape3D into Head in the scene tree and it’ll automatically inherit it’s rotation.