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

I have problems when i put isonfloor, without isonfloor my character jumps, but when I put it, my character stop jumping, can someone help me?


extends Actor

const JUMPFORCE = -1000
const SPEED = 300
const GRAVITY = 30

func getinput():
velocity = Vector2(0,100)
velocity.x = SPEED
if Input.isactionpressed('moveleft'):
velocity.x = -SPEED
actionjustpressed('jump') and isonfloor():
velocity.y = JUMPFORCE

    velocity.y = velocity.y  + GRAVITY

func physicsprocess(delta):
velocity = move

velocity.x = lerp(velocity.x,0,0.2)

Godot 3.2

in Engine by (12 points)

What is Actor? Maybe this should be KinematicBody2D? (just guessing)

the rest looks good to me...
why are you doing:

func getinput():
    velocity = Vector2(0, 100) # <------


Are you sure isonfloor is ever true? (just add print(is_on_floor()) somewhere, and see the output)

2 Recommandations:
1. you are defining you constants as integers. Then you use them to calculate velocity which is a Vector2 (2 floats). In your case, this works perfectly fine, but can lead to horrifix bugs, that are hard to find.
Try this, and you'll understand:

print(1 / 10) # Output: 0
print(1.0 / 10.0) # Output: 0.1

2. You should not change velocity in you get_input().
It's work and is fine, if you have very simple scripts, but makes debugging harder as it should be.
It's better to calculate a relative Vector2 to your actual velocity, return it, and set/add/wahtever it to the actual velocity:

velocity += get_input()

give velocity as an argument, calculate stuff, return it, and set it to the new velocity:

velocity = get_input(velocity)

if you change variables in functions, it becomes very fast very unclear what happens to variables and there values where and when.
If you use the return, it's very clear what happens to the velocity at that point.
In this case it's extra missleading, because the function is "getinput". This should get the input and not "calculatenew_velocity". Hope you get what i mean.

Please log in or register to answer this question.

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.