Multiple issues and i tried solutions i could think of non seemed to work

Godot Version

4.2

Question

1: horizontal movement still works works when crouching even after i set a crouching state and setting horizontal movement to a true or false statement.

2: wall jumping just doesnt work, i mean it DOES but when i touch a wall it crashes completely

3: super jumping is by far the worst offender, not only do it NOT work, IT ALSO BROKE THE NORMAL JUMP
*jumps all the way to (presuming) max height at a super fast speed.

  • holding down crouch, some how lets me glide for a short time period???
  • i can infinitly jump despite having a max jump and jump counter.

heres the whole code

@onready var parasol_girl = $AnimatedSprite2D
@onready var collision = $CollissionShape2D
@onready var dash_shape = $dash_shape
@onready var crouch_shape = $crouch_shape
#const SPEED = 400.0 # Imahilus doesn't appear to be used
var speed = 350.0
# Jumping variables
const JUMP_VELOCITY = -480.0
const FAST_FALL_VELOCITY = 1000
var jump_count = 0
var max_jumps = 2
var fast_fall = false
# Dashing variables
const DASH_SPEED = 2000
var dash_state = false
@export var dash_duration = 0.1
var time_spent_dashing = 0
@export var dash_cooldown = 1
var time_dash_spent_on_cooldown = 0
@onready var second_jump: bool = false
# Get the gravity from the project settings to be synced with RigidBody nodes.
var gravity = ProjectSettings.get_setting("physics/2d/default_gravity")
var is_crouching = false
var vertical_direction = Input.get_axis("ui_down","ui_up")
var super_jump = false
var super_jump_height = -480


func _physics_process(delta):
	var horizontal_direction = Input.get_axis("ui_left","ui_right")
	# Imahilus: I've commented this out, as the physics engine will apply the gravity to CharacterBody2D if 'motion_mode' is set to 'grounded' in the Inspector
	#Add the gravity.
	if not is_on_floor():
		velocity.y += gravity * delta
	
	# Time to handle the jump
	if is_on_floor():
		# We're on the floor, let's reset any jumps including the 'downwards jump'
		jump_count = 0
		fast_fall = false
	
	if Input.is_action_just_pressed("jump") and jump_count < max_jumps:
		is_crouching = false
		jump_count += 1
		velocity.y += JUMP_VELOCITY
		
	if !fast_fall and Input.is_action_just_pressed("ui_down") and !is_on_floor():
		# If no 'downwards jump' has been triggered yet, we press the button to 'downward jump' AND we're not on the floor, do the drop!
		fast_fall = true
		jump_count = max_jumps # if we jump downwards.. no more jumping up!
		
	if Input.is_action_pressed("jump") and ("ui_down"):
		super_jump = true
		velocity.y += super_jump_height
		is_crouching = false 
		jump_count += 1
		
	if fast_fall:
		# we're jumping downwards!! wheeee!
		velocity.y = FAST_FALL_VELOCITY
	
	
	# Imahilus: I've commented this out, and rewritten this above
	#if Input.is_action_pressed("ui_down"):
	#	velocity.y = velocity.y +70
	
	#if is_on_floor():
	#	jump_count = 0
	
	# Handle jump.
	#if Input.is_action_just_pressed("ui_accept") and jump_count < max_jumps:
	#	if jump_count==0:
	#		velocity.y = JUMP_VELOCITY
	#		jump_count += 1
	#	elif jump_count==1:
	#		velocity.y= JUMP_VELOCITY+double_jump
	#		jump_count+=1
		
			
			# Get the input direction and handle the movement/deceleration.
	# As good practice, you should replace UI actions with custom gameplay actions.
	#	if Input.is_action_just_pressed("ui_accept") and jump_count < max_jumps:
	#		if jump_count==0:
	#			velocity.y = JUMP_VELOCITY
	#			jump_count += 1
	#		elif jump_count==1:
	#			velocity.y= JUMP_VELOCITY*double_jump
	#			jump_count+=1
		
		
	# Get the input direction and handle the movement/deceleration.
	# As good practice, you should replace UI actions with custom gameplay actions.
	if Input.is_action_just_pressed("Dash") and time_dash_spent_on_cooldown >= dash_cooldown: # If the button is pressed, and the last time Dash was used is longer than the cooldown time ago, we can dash!
		dash_state = true
		time_spent_dashing = 0 # reset the time we've spent Dashing
		time_dash_spent_on_cooldown = 0 # reset the cooldown on the Dash
		
	if dash_state:
		collision.disabled = true
		dash_shape.disabled= false
		velocity.y = 0
	else:
		collision.disabled = false
		dash_shape.disabled = true
	
	if dash_state:
		# We're dashing!!
		
		# Lets update the timers of the dash, so we don't permanently dash
		time_spent_dashing += delta
		if time_spent_dashing >= dash_duration:
			dash_state = false # We've spent more time dashing than was set, so we need to stop
		
		# Now lets actually do the dash part of it
		if parasol_girl.flip_h == false:
			# If parasol_girl is facing right; we dash to the right
			velocity.x = DASH_SPEED
		else:
			# If parasol_girl is facing left; we dash to the left
			velocity.x = -DASH_SPEED
	else:
		# We're not dashing... so we can look at normal input. We separate these 2 so that user controls can't influence the dash
			velocity.x = speed * horizontal_direction
	if velocity.x > 0:
		parasol_girl.flip_h = false
	elif velocity.x < 0:
		parasol_girl.flip_h = true
	
	# Last thing to do, if Dash is on cooldown, we need to count this time towards the cooldown, otherwise it won't come back
	# This can't be in with the Dash code because it has to happen regardless of whether we're dashing
	if time_dash_spent_on_cooldown < dash_cooldown:
		# We only need to do this until we've waited long enough (see line 67; until time_dash_spent_on_cooldown is more or equal to dash_cooldown)
		time_dash_spent_on_cooldown += delta
		
	if is_on_wall():
		var wall_normal = get_last_slide_collision().get_normal()
		velocity.x = wall_normal * speed
		velocity.y = 30
		jump_count = 1
	
	
	if velocity.x != 0:
		print (str(velocity.x))
		
	# Regardless of what we did in any if statement, if parasol_girl has any velocity, let the physics engine move her
	move_and_slide()
	if horizontal_direction:
		parasol_girl.play("running")
		
	elif velocity.x >= 0:
		parasol_girl.play("idle")
		
	if jump_count >=1:
		parasol_girl.play("jumping")
	if jump_count >=2:
		parasol_girl.play("double_jump")
		
	if Input.is_action_pressed("ui_down"):
		is_crouching == true
		parasol_girl.play("crouching")
		collision.disabled = true
		crouch_shape.disabled = false
		horizontal_direction = false
		
	elif Input.is_action_just_released("ui_down"):
		is_crouching =  false
		horizontal_direction = true
		collision.disabled = false
		crouch_shape.disabled = true
		
	if velocity.y >= 1:
		parasol_girl.play("falling")
	if dash_state:
		parasol_girl.play("dashing")

	if is_crouching == false:
		horizontal_direction = false

Please paste your code between three ticks. press the </> button on a new line to create them easily like so

```
type or paste code here
```

When I encouraged making a new post I ment it should focus on one issue. Could you post what error messages you are recieving, what do you mean by “crashing”

1 Like

done and done

1 Crouching

two equal signs is a comparison, not assignment. You should get a warning along the lines of “Standalone expression (the line has no effect)”. change this to is_crouching = true

you also only use is_crouching for this expression

Since horizontal_dircection isn’t used after this point it is useless to set it to false, which also does not do what you might expect, you would want to set it to Vector2.ZERO. move this up, right after creating horizontal_direction

func _physics_process(delta):
	var horizontal_direction = Input.get_axis("ui_left","ui_right")
	if is_crouching:
		horizontal_direction = Vector2.ZERO

2 Wall jump

There is no input check for jumping, so touching a wall would trigger the wall jump without any input. Try to combine this lone if is_on_wall(): with a jump check

if Input.is_action_pressed("jump") and is_on_wall():
	var wall_normal = get_last_slide_collision().get_normal()
	velocity.x = wall_normal * speed
	velocity.y = 30
	jump_count = 1

3 Super jump

The if condition is not checking for down input, just the down string which is always true.

Your jump and super jump trigger at the same time, netting double jump height. Nest the if statements to only apply jump height once.

if Input.is_action_just_pressed("jump") and jump_count < max_jumps:
	is_crouching = false
	jump_count += 1
	if Input.is_action_pressed("ui_down"):
		velocity.y += super_jump_height
		super_jump = true
	else:
		velocity.y += JUMP_VELOCITY


tried fixing the issue my self and looking through your comments and reading the code, but i found another issue, loading up the game puts me to the ceiling, and if i touch the ground i instantly get bounced back up staying there i can still fast fall and more horizontally but im just stuck on the ceiling ._.

Very silly of me, you are just using get_axis not get_vector. Try this snippet instead

func _physics_process(delta):
	var horizontal_direction = Input.get_axis("ui_left","ui_right")
	if is_crouching:
		horizontal_direction = 0.0

well while i can no longer move when crouching (good), the game still forces me up to the ceiling and bounces me back on to the ground

and jumping off a wall when wall jumping crashes the game

Could you post the edited script and please explain what you mean by “wall jumping crashes the game”? Is there any error message, is it a stack trace? please show either or both of those.

“invalid index ‘x’ (on base: vector2) with value type of ‘vector2’” this error appears when i wall jump off a wall

		var wall_normal = get_last_slide_collision().get_normal()
		velocity.x = wall_normal * speed
		velocity.y = 30
		jump_count = 1```

![image_2024-06-27_152337623|690x387](upload://t51zirii1kJWELuGtUrYVdaWPy9.png)
![image_2024-06-27_152344773|690x387](upload://8bbReUvdH7uTlvL7OaS05LxXdEI.png)
var wall_normal = get_last_slide_collision().get_normal()
velocity.x = wall_normal.x * speed
velocity.y = 30

only use the wall normal’s x value