Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- extends '../Movement.gd'
- export(float) var BASE_MAX_HORIZONTAL_SPEED = 400.0
- export(float) var AIR_ACCELERATION = 1000.0
- export(float) var AIR_DECCELERATION = 2000.0
- export(float) var AIR_STEERING_POWER = 50.0
- export(float) var GRAVITY = 1600.0
- var enter_velocity = 0.0
- var max_horizontal_speed = 0.0
- var horizontal_speed = 0.0
- var horizontal_velocity = 0.0
- func initialize(speed, velocity):
- horizontal_speed = speed
- max_horizontal_speed = speed if speed > 0.0 else BASE_MAX_HORIZONTAL_SPEED
- enter_velocity = velocity
- func enter():
- var input_direction = get_input_direction()
- #get_input_direction get's the input direction normal.
- #For exmple, if A and D are pressed, it returns 0. If D is pressed, 1, and vice-versa
- if owner.is_on_floor():
- emit_signal("finished", "previous")
- func update(delta):
- var input_direction = get_input_direction()
- update_look_direction(input_direction)
- fall(delta, input_direction)
- print(owner.is_on_floor())
- if owner.is_on_floor():
- emit_signal("finished", "previous")
- ### VVV THIS FUNCTION MOST LIKELY PRODUCES THE BUG VVV
- func fall(delta, direction):
- if Input.is_action_pressed("snapshot"):
- return
- if direction:
- horizontal_speed += AIR_ACCELERATION * delta
- else:
- horizontal_speed -= AIR_DECCELERATION * delta
- horizontal_speed = clamp(horizontal_speed, 0, max_horizontal_speed)
- var target_velocity = horizontal_speed * direction
- var steering_velocity = (target_velocity - horizontal_velocity) * AIR_STEERING_POWER
- horizontal_velocity += steering_velocity
- owner.move_and_slide(Vector2(horizontal_velocity, 0))
- #I'm hoping to incorporate vertical velocity or gravity in this Vector2 at some point
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement