0

I'm trying to make this script make the ground still. When the player jumps it is supposed to make the ground and start moving and not stop. But, it is only moving when the player jumps.

My Code:

extends Area2D

#Script-Purpose: move and delete ground

#Ground moving speed
const SPEED = -150

#a vector2 to change the speed of the ground
var velocity = Vector2()

#to check if you have jumped yet
var Jumped=false

#calls Physics
func _physics_process(delta):

        #left-click=jump
    if Input.is_action_pressed("ui_jump"):
        Jumped=true

    #make the velocity.x equal to speed accounted with delta time
    if Jumped==true:
        print(Jumped)
        velocity.x = SPEED * delta
        translate(velocity)
    else:
                #this is here so I can check if the Jumped var is false
        print(Jumped)

Jumped is false half the time and true for the other half.

robsiemb
  • 6,157
  • 7
  • 32
  • 46
  • Hi, could you clarify what behavior you are expecting? In the code above, the Area2D never stops once you have left clicked because `Jumped` is never set back to false. – hola Oct 30 '19 at 00:36
  • I agree with hola. Put an `else: Jumped=false` after your `if` statement, and possibly consider using `is_action_just_pressed` instead of `is_action_pressed`, if you only want the jump to trigger once per input press. – Christopher Bennett Oct 30 '19 at 02:11
  • I'm sorry I didn't reply sooner. I want for jumped to be false when the game starts and when you jump it sets to true and keeps moving the ground forever after that. – orion Flame Nov 05 '19 at 01:32
  • So just to clarify. You want to start the game with the world not moving, and when the player left-clicks (jumps), the world begins moving (velocity * speed * delta) and keeps moving for the rest of the game? Maybe try defining `var Jumped` ( just like that - plain with no =) at the top, and then in your `ready()` function, declare `Jumped=false`. Then you can set it to true using the `physics_process()`.as you have already written. Just a guess as I cannot test it where I am now. – Christopher Bennett Nov 06 '19 at 15:06
  • I don't really understand what is your problem, but can it be that you press a button to enter the scene and it triggers the input? and I have a siggestion, if I understand what do you want to do, insted of mooving all the grown you can moove the camera and if the player mooves with the same velociti if its like geometry dach or dies if goes aoutside the window (depending of what you want to do) I hope it hepls. – Joel Imbergamo Feb 07 '20 at 22:08

0 Answers0