Any one see this

Godot Version

godot 4

Question

why line21 warning come ???

code:
extends RigidBody3D

var mouse_sensitivity := 0.001
var twist_input := 0.0
var pitch_input := 0.0

@onready var twist_pivot := $TwistPivot
@onready var pitch_pivot := $TwistPivot/PitchPivot

func _ready() → void:
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)

Called every frame. ‘delta’ is the elapsed time since the previous frame.

func _process(delta: float) → void:
var input := Vector3.ZERO
input.x = Input.get_axis(“left”, “right”)
input.z = Input.get_axis(“up”, “dwon”)

apply_central_force(twist_pivot.basis * input * 1200.0 * delta)

var aligned_force = twist_pivot.basis * input

if Input.is_action_just_pressed("mouse"):
	Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE)
	
twist_pivot.rotate_y(twist_input)
pitch_pivot.rotate_x(pitch_input)
pitch_pivot.rotation.x = clamp(pitch_pivot.rotation.x, 
	deg_to_rad(-30), 
	deg_to_rad(30)
)
twist_input = 0.0
pitch_input = 0.0

func _unhandled_input(event: InputEvent) → void:
if event is InputEventMouseMotion:
if Input.get_mouse_mode() == Input.MOUSE_MODE_CAPTURED:
twist_input = - event.relative.x * mouse_sensitivity
pitch_input = - event.relative.y * mouse_sensitivity

As it says you never use aligned_force again

If you don’t intend to use it delete the variable.

If you want to use it, use it.

If you don’t like the warning remove reporting by going to ProjectSettings, enable advance settings, → Debug → gdscript → unused variable.

The main reason it warns you is that it is just wasted processing to make a variable but never use it. It’s nice for refactors when you forget to remove something you don’t need anymore.

3 Likes

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