So i did this code AGES ago and cant figure out what I was doing or if I was watching a tutorial or not. But my main issue is that the camera keeps clipping through the enviroment. I thought that having the camera spring position assigned would carry on the effects of the spring arms collisions. Camera works just fine orbits around/ I have played with the collisions on the raycast on the spring arm but it doesn’t seem to work. Kinda stuck and don’t want to reformat all the code since I made it to work with controllers any ideas?
Make sure to paste code instead of screenshots; if spring_arm is assigned to the actual spring arm then it’s .position will not be where it collided, but where it starts, which may not be useful to you. You could use the node as a direct child of the spring arm though.
Are you sure your spring arm is set up correctly?
I’m not sure it is set up correctly issue is if I have the camera inherited below the spring arm it just seems to break and stick at the characters feed but with the code I have set up I am not entirely sure how to reset it (also ill post the code instead of screenshots!)
PlayerSCRIPT →
extends CharacterBody3D
@export var Speed = 10.0
@export var JumpStrength = 9.0
@export var Gravity = 25.0
var Velocity = Vector3.DOWN
var SnapVector = Vector3.DOWN
@onready var Cam_Pivot = $CameraPivot
@onready var Model = %BodyMesh
func _physics_process(delta):
Movement(delta)
func _process(_delta):
window_activity()
Cam_Pivot.position = position
func Movement(delta):
var MoveDir = Vector3.ZERO
MoveDir.x = Input.get_action_strength(“move_right_1”) - Input.get_action_strength(“move_left_1”)
MoveDir.z = Input.get_action_strength(“move_backward_1”) - Input.get_action_strength(“move_forward_1”)
MoveDir = MoveDir.rotated(Vector3.UP, Cam_Pivot.rotation.y).normalized()
Velocity.x = MoveDir.x * Speed
Velocity.z = MoveDir.z * Speed
Velocity.y -= Gravity * delta
var JustLanded = is_on_floor() and SnapVector == Vector3.ZERO
if Input.is_action_just_pressed("jump_1") and is_on_floor():
Velocity.y = JumpStrength
SnapVector = Vector3.ZERO
elif JustLanded:
SnapVector = Vector3.DOWN
set_velocity(Velocity)
set_up_direction(Vector3.UP)
set_floor_stop_on_slope_enabled(true)
move_and_slide()
Velocity = velocity
if Velocity.length() > 0.2:
var LookDirection = Vector2(Velocity.z, Velocity.x)
Model.rotation.y = lerp_angle(Model.rotation.y, LookDirection.angle(), delta*5)
func window_activity():
if Input.is_action_just_pressed(“ui_cancel”) or Input.is_action_just_pressed(“Fullscreen”):
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)
SpringARM3d SCRIPT→
extends Node3D
@export var mouse_sens: = 0.005
@export var gamepad_sens: = 2.0
@onready var spring_arm := %CamArm
var player_id = 1
func _ready() → void:
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
func _unhandled_input(event: InputEvent) → void:
Handle Mouse Input
if event is InputEventMouseMotion:
rotate_camera(event.relative.x * mouse_sens, event.relative.y * mouse_sens)
func *process(delta: float) → void:
Handle Gamepad Input
var look_x = Input.get_action_strength(“camera_right*%s” % player_id) - Input.get_action_strength(“camera_left_%s” % player_id)
var look_y = Input.get_action_strength(“camera_down_%s” % player_id) - Input.get_action_strength(“camera_up_%s” % player_id)
if abs(look_x) > 0.1 or abs(look_y) > 0.1: # Apply deadzone
rotate_camera(look_x * gamepad_sens * delta, look_y * gamepad_sens * delta)
# Keep the camera at the player's position
global_position = $"..".global_position
func rotate_camera(delta_x: float, delta_y: float) → void:
rotation.y -= delta_x
rotation.y = wrap(rotation.y, 0.0, TAU)
rotation.x -= delta_y
rotation.x = clamp(rotation.x, -PI/2, PI/4)
Camera3D Script →
extends Camera3D
@export var spring_arm: Node3D /* connects springarm position to camera for camera to inherit */
@export var lerp_power: float = 1.0
func _process(delta: float) → void:
position = lerp(position, spring_arm.position, delta*lerp_power)
also sorry not sure exactly how to format code for the godot forums (hopefully someone knows how to mess with this if not Ill start from the ground up!)





