Change height of GoDot CollisionShape3D? GoDot4?

Hello. I've been working with the GoDot game engine for about a week, but I'm not really making much progress. Unfortunately, I haven't found a solution to my problem online. I would be grateful if someone here knows how to write the script:

I'm currently in the process of creating a controllable player and have it finished, except for the one thing that doesn't work.

My goal is to allow the player to duck. To do this, I want to change the height of the Collisionshape3D from 2 to 1 while Input.is_action_pressed("sneak"): is active. Upon release (else), it should be set back to 2.

Here is the structure of my nodes for the player:

 Player (ist ein Node3D) CharacterBody3D CollisionShape3D Camera3D

And here is my script, which is responsible for the movement:

 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()
1 vote, average: 1.00 out of 1 (1 rating, 1 votes, rated)
You need to be a registered member to rate this.
Loading...
Subscribe
Notify of
5 Answers
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
paaauleee
1 year ago

This had to be done via scale.y – and possibly also adjust the position of the CollisionShapes at a crouched position

 func _input(event): if event.is_action_pressed("ducken"): $"CollisionShape3D".scale.y = 1 else: $"CollisionShape3D".scale.y = 2
paaauleee
1 year ago
Reply to  PhantoX666

No problem.

– But okay, you can also directly adjust the "height" value of the CollisionShape:

 $"CollisionShape3D".shape.height = 1
paaauleee
1 year ago

Addendum – I've just tested this – also works:-) – problem is the input event in general….how exactly would that do? So, as long as the "show" button is pressed, it's supposed to duck – and just press the button briefly and it's still evacuated and just stand up again in another action?