Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Zizico2 |
export var player_speed = 900
export var jumpforce = 200
export var acceleration = 5
var raycast_down = null
var current_speed = 0
var btn_right
var btn_left
var btn_jump
func move(speed, acc, delta):
current_speed = lerp(current_speed , speed, acc * delta)
linear_velocity.x = current_speed
func is_on_ground():
if raycast_down.is_colliding():
return true
else:
return false
func _ready():
raycast_down = get_node("RayCast2D")
raycast_down.add_exception(self)
func _process(delta):
btn_left = Input.is_action_pressed("ui_left")
btn_right = Input.is_action_pressed("ui_right")
btn_jump = Input.is_action_just_pressed("ui_jump")
if btn_left:
move(-player_speed, acceleration, delta)
elif btn_right:
move(player_speed, acceleration, delta)
else:
move(0, acceleration, delta)
if is_on_ground():
if btn_jump:
linear_velocity.y = jumpforce
Here’s my code. Idk what’s wrong. And another question. I’m teasting this in a floating platform so I can still test gravity just by walking out of the platform. And no matter how mutch i increase mass and gravity scale the character always falls down at the same speed. ?!?!
Thanks in advance.