GoDot CollisionShape3D höhe ändern? GoDot4?

Hallo. Ich beschäftige mich seit ca. einer Woche mit der GameEngine GoDot, komme aber nicht wirklich weiter. Im Internet habe ich zu meinem Problem leider keine Lösung gefunden. Ich würde mich freuen, wenn hier jemand weiß, wie ich das Script schreiben muss:

Ich bin gerade dabei, einen steuerbaren Spieler zu erstellen, hab ihn auch, bis auf den einen Punkt, der nicht funktioniert auch schon fertig.

Mein Ziel ist es, dass der Spieler sich ducken kann. Dazu möchte ich die height des Collisionshape3D von 2 auf 1 ändern, wärend Input.is_action_pressed("sneak"): aktiv ist. Beim loslassen (else) es wieder auf 2 gestellt werden.

Hier der Aufbau meiner Nodes für den Spieler:

Player (ist ein Node3D)
     CharacterBody3D
       CollisionShape3D
       Camera3D
        

Und hier mein Script, welches für das Movement vernatwortlich ist:

extends CharacterBody3D

@onready var Camera3D2CharacterBody = $"Camera3D"
var SPEED = 7.0
var JUMP_VELOCITY = 6
var CAN_JUMP = true

# Get the gravity
var gravity = ProjectSettings.get_setting("physics/3d/default_gravity")

# Get Userinputs
func _input(event):
	if event is InputEventMouseMotion:
		var rotation_speed = event.relative.x * Camera3D2CharacterBody.sensitivity
		rotate_y(deg_to_rad(-rotation_speed))
	# Sneaken und sprinten
	if Input.is_action_pressed("sneak"):
		SPEED = 3
		Camera3D2CharacterBody.position.y = 0.3
		# Hier soll die Zeile hin, die die Höhe von CollisionShape3D auf 1 setzt.
	elif Input.is_action_pressed("sprint"):
		SPEED = 11.0
	else:
		SPEED = 7.0
		# Hier soll die Zeile hin, die die Höhe von CollisionShape3D wieder auf 2 setzt.
		Camera3D2CharacterBody.position.y = 0.629


func _physics_process(delta):
	# Add the gravity.
	if not is_on_floor():
		velocity.y -= gravity * delta
	# Handle Jump.
	if Input.is_action_just_pressed("jump") and is_on_floor():
		velocity.y = JUMP_VELOCITY
		CAN_JUMP = true
	if Input.is_action_just_pressed("jump") and CAN_JUMP:
		velocity.y = JUMP_VELOCITY
		CAN_JUMP = false
	if is_on_floor():
		CAN_JUMP = true


	# Get the input direction and handle the movement/deceleration.
	# As good practice, you should replace UI actions with custom gameplay actions.
	var input_dir = Input.get_vector("laufen_links", "laufen_rechts", "laufen_vorwärts", "laufen_rückwärts")
	var direction = (transform.basis * Vector3(input_dir.x, 0, input_dir.y)).normalized()
	if direction:
		velocity.x = direction.x * SPEED
		velocity.z = direction.z * SPEED
	else:
		velocity.x = move_toward(velocity.x, 0, SPEED)
		velocity.z = move_toward(velocity.z, 0, SPEED)


	move_and_slide()
godot, Godot Game Engine

Meistgelesene Fragen zum Thema Godot