Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Shihab |
HI,
the is_on_floor()
is not working properley.
when I try to jump :
if Input.is_action_just_pressed("jump") and is_on_floor():
velocity.y = jump_force
is not working but this will be work? :
if Input.is_action_just_pressed("jump"):
velocity.y = jump_force
Help
The code:
extends KinematicBody2D
export var gravity = 20;
export var speed = 10;
export var jump_force = -1000;
var velocity = Vector2(0,0)
func _physics_process(delta):
if Input.is_action_pressed("ui_right"):
velocity.x = speed * 100
elif Input.is_action_pressed("ui_left"):
velocity.x = -speed * 20
velocity.y = velocity.y + gravity
if Input.is_action_just_pressed("jump") and is_on_floor():
velocity.y = jump_force
velocity = move_and_slide(velocity)
velocity.x = lerp(velocity.x,0,0.2)
Thinks
Please post your code properly, it is impossible to read like this.
When posting your question, there is a “Code Sample” button, it looks like {}
.
kidscancode | 2021-01-27 19:05