Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | YayIguess | |
Old Version | Published before Godot 3 was released. |
So I had this working before, but once I moved all of my input into the _input
function it broke. I had it so when my kinematicbody2d charcter jumped, if he was moving forward, he would keep that momuntum and then jump forward, but once I moved my input handling into the _input
function, this doesn’t happen and instead as soon as he jumps he loses all horizontal momentum and jumps completely vertically, I’m a newb at godot and game develpoment in general so sorry if this is me using the built-in functions incorrectly. (When I had my input inside _fixed_process
jumping wasn’t working correctly as I could just hold down jump and weird stuff would happen).
script:
extends KinematicBody2D
var gravity = globals.gravity
var movement = Vector2()
var WALK_SPEED = 675
var JUMP_SPEED = 675
var FAST_FALL_SPEED = 750
var CAN_DOUBLE_JUMP = false
func _on_ground():
return test_move(Vector2(0, 1))
func _input(event):
#if (event.is_action_pressed("ui_accept") && event.is_action_pressed("ui_select")):
# get_tree().reload_current_scene()
if (event.is_action_pressed("move_l")):
movement.x = -WALK_SPEED
elif (event.is_action_pressed("move_r")):
movement.x = WALK_SPEED
else:
movement.x = 0
if(event.is_action_pressed("jump")):
if(_on_ground()):
movement.y = -JUMP_SPEED
CAN_DOUBLE_JUMP = true
elif(CAN_DOUBLE_JUMP == true):
movement.y = -JUMP_SPEED
CAN_DOUBLE_JUMP = false
if(!_on_ground()):
if(event.is_action_pressed("fast_fall")):
movement.y = FAST_FALL_SPEED
func _fixed_process(delta):
movement.y += delta * gravity
var motion = movement * delta
move(motion)
if (is_colliding()):
var n = get_collision_normal()
motion = n.slide(motion)
movement = n.slide(movement)