Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- extends CharacterBody2D
- @onready var player_value = "res://DefaultMovementData.tres"
- @export var movement_data : PlayerMovementData
- var motion = Vector2()
- var motion_prev = Vector2()
- var gravity = ProjectSettings.get_setting("physics/2d/default_gravity")
- var hit_the_ground = false
- #@onready var animated_sprite_2d = $AnimatedSprite2D
- @onready var cayote_jump_timer = $CayoteJumpTimer
- @onready var starting_pos = global_position
- func _physics_process(delta):
- apply_gravity(delta)
- handle_jump()
- var input_axis = Input.get_axis("Left", "Right ")
- handle_acceleration(input_axis,delta)
- apply_friction(input_axis, delta)
- apply_air_resistance(input_axis,delta)
- update_animations(input_axis)
- var was_on_floor = is_on_floor()
- move_and_slide()
- var just_left_ledge = was_on_floor and not is_on_floor() and velocity.y >= 0
- if just_left_ledge:
- cayote_jump_timer.start()
- func apply_gravity(delta):
- if not is_on_floor():
- velocity.y += gravity * movement_data.gravity_scale * delta
- func handle_jump():
- if is_on_floor() or cayote_jump_timer.time_left > 0.0:
- if Input.is_action_just_pressed("ui_up"):
- velocity.y = movement_data.jump_velocity
- if not is_on_floor():
- if Input.is_action_just_released("ui_up") and velocity.y < movement_data.jump_velocity / 2 :
- velocity.y = movement_data.jump_velocity / 2
- func handle_acceleration(input_axis,delta):
- if input_axis !=0:
- velocity.x = move_toward(velocity.x,movement_data.speed * input_axis , movement_data.acceleration * delta)
- func apply_friction(input_axis ,delta):
- if input_axis == 0 and is_on_floor():
- velocity.x = move_toward(velocity.x, 0 , movement_data.friction * delta)
- func apply_air_resistance(input_axis , delta):
- if input_axis == 0 and not is_on_floor():
- velocity.x = move_toward(velocity.x, 0,movement_data.air_resistance * delta)
- pass
- func update_animations(input_axis):
- pass
- func _on_hazard_detector_area_entered(area):
- global_position = starting_pos
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement