This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
0 votes

Jump script is not working please help

script: extends KinematicBody2D

export var velocity = Vector2.ZERO
export var speed = Vector2(300.0,300.0)
export var gravity = 300.0
var Accel = 10
const UP = Vector2(0, -100)
const JUMP = -10

func _process(delta: float) -> void:

if Input.is_action_pressed("ui_right"):
    velocity.x += gravity * delta
    velocity.x = max(velocity.x , speed.x)
if Input.is_action_just_released("ui_right"):
    velocity.x = 0
if Input.is_action_pressed("ui_left"):
    velocity.x -= gravity * delta
if Input.is_action_just_released("ui_left"):
    velocity.x = 0

func physicsprocess(delta: float) -> void:
velocity.y = gravity
if Input.isactionjustpressed("uiup"):
velocity.y = -25

    velocity = move_and_slide(velocity,UP)
Godot version 3.2
in Engine by (12 points)

You should use func _input

1 Answer

0 votes

An easy way to do jumping is to add "jump" to the input map then right this code:

func getdirection() -> Vector2:
-1.0 if Input.is
actionjustpressed("jump") and isonfloor() else 1.0)

by (93 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.