For some reason my camera controller continues to drift after mouse movement has stopped.
-
For some reason my camera controller continues to drift after mouse movement has stopped.
I can't seem to figure out why this is happening or how to stop it, since I'm new to using Godot
Code for the camera controller:
#Godot #GameDev #Debuggingextends RigidBody3D var mouse_sensitivity := 0.01 var yaw_input := 0.0 var pitch_input := 0.0 # Called when the node enters the scene tree for the first time. func _ready(): # Lock mouse to game window Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED) # Called every frame. 'delta' is the elapsed time since the previous frame. func _process(delta): # Adjust camera yaw using mouse input $YawPivot.rotate_y(yaw_input) # Adjust camera pitch using mouse input $YawPivot/PitchPivot.rotate_x(pitch_input) # Lock camera pitch between 0.75 and -0.75 radians $YawPivot/PitchPivot.rotation.x = clamp( $YawPivot/PitchPivot.rotation.x, -0.75, # Negative pitch limit 0.75 # Positive pitch limit ) func _unhandled_input(event: InputEvent): # Get mouse movements when captured if event is InputEventMouseMotion: if Input.get_mouse_mode() == Input.MOUSE_MODE_CAPTURED: yaw_input = - event.relative.x * mouse_sensitivity pitch_input = - event.relative.y * mouse_sensitivity
-
P [email protected] shared this topic
-
For some reason my camera controller continues to drift after mouse movement has stopped.
I can't seem to figure out why this is happening or how to stop it, since I'm new to using Godot
Code for the camera controller:
#Godot #GameDev #Debuggingextends RigidBody3D var mouse_sensitivity := 0.01 var yaw_input := 0.0 var pitch_input := 0.0 # Called when the node enters the scene tree for the first time. func _ready(): # Lock mouse to game window Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED) # Called every frame. 'delta' is the elapsed time since the previous frame. func _process(delta): # Adjust camera yaw using mouse input $YawPivot.rotate_y(yaw_input) # Adjust camera pitch using mouse input $YawPivot/PitchPivot.rotate_x(pitch_input) # Lock camera pitch between 0.75 and -0.75 radians $YawPivot/PitchPivot.rotation.x = clamp( $YawPivot/PitchPivot.rotation.x, -0.75, # Negative pitch limit 0.75 # Positive pitch limit ) func _unhandled_input(event: InputEvent): # Get mouse movements when captured if event is InputEventMouseMotion: if Input.get_mouse_mode() == Input.MOUSE_MODE_CAPTURED: yaw_input = - event.relative.x * mouse_sensitivity pitch_input = - event.relative.y * mouse_sensitivity
@CrebboElodie Minor nitpick but
if Input.get_mouse_mode() == Input.MOUSE_MODE_CAPTURED: yaw_input = - event.relative.x * mouse_sensitivity pitch_input = - event.relative.y * mouse_sensitivity
Does GDScript not have the operator=-
? It's hard for me to tell what you're trying to do here. This is a bit ambiguous, usually I try to use parenthesis. there are a couple of interpretations for this:if Input.get_mouse_mode() == Input.MOUSE_MODE_CAPTURED: yaw_input =- (event.relative.x * mouse_sensitivity) pitch_input =- (event.relative.y * mouse_sensitivity)
if Input.get_mouse_mode() == Input.MOUSE_MODE_CAPTURED: yaw_input = (-event.relative.x) * mouse_sensitivity pitch_input = (-event.relative.y) * mouse_sensitivity
if Input.get_mouse_mode() == Input.MOUSE_MODE_CAPTURED: yaw_input = -(event.relative.x * mouse_sensitivity) pitch_input = -(event.relative.y * mouse_sensitivity)
-
@CrebboElodie Minor nitpick but
if Input.get_mouse_mode() == Input.MOUSE_MODE_CAPTURED: yaw_input = - event.relative.x * mouse_sensitivity pitch_input = - event.relative.y * mouse_sensitivity
Does GDScript not have the operator=-
? It's hard for me to tell what you're trying to do here. This is a bit ambiguous, usually I try to use parenthesis. there are a couple of interpretations for this:if Input.get_mouse_mode() == Input.MOUSE_MODE_CAPTURED: yaw_input =- (event.relative.x * mouse_sensitivity) pitch_input =- (event.relative.y * mouse_sensitivity)
if Input.get_mouse_mode() == Input.MOUSE_MODE_CAPTURED: yaw_input = (-event.relative.x) * mouse_sensitivity pitch_input = (-event.relative.y) * mouse_sensitivity
if Input.get_mouse_mode() == Input.MOUSE_MODE_CAPTURED: yaw_input = -(event.relative.x * mouse_sensitivity) pitch_input = -(event.relative.y * mouse_sensitivity)
@[email protected] @[email protected] GDScript has -= but they're not trying to do that
-
@[email protected] @[email protected] GDScript has -= but they're not trying to do that
@[email protected] @[email protected] yeah. i mean just personally i always try to show what order i am trying to process things. it probably isn't even related to the root issue.