Spawned bullets in Godot are oriented wrongly - godot

I'm trying to make the player shoot bullets out
The thing is, they're not pointing in the same direction as the player
They also do not follow the player as they move around
code for the bullet
I store the object that shot the bullet so that the bullet can signal back if it has hit something
extends KinematicBody
var time = 0
var speed = 1800
var velocity = Vector3()
var collision = NAN
# stores the object that shot it
var shooter = NAN
func start(own):
shooter = own
# TODO Finish
global_transform.basis = own.global_transform.basis
velocity = own.global_transform.basis.z * speed + own.velocity
func _process(delta):
collision = move_and_collide(velocity * delta)
if collision:
# get parent of the StaticBody or RigidBody
print(collision.collider.get_parent())
queue_free()
time += delta
if time > 3:
queue_free()
Code for the Player
extends KinematicBody
var velocity = Vector3()
var acceleration = 1
var retrograde = false
var mouse_sensitivity = 0.008
var rot_x_target = 0
var rot_y_target = 0
var rot_x_speed = 0
var rot_y_speed = 0
var rot_acceleration = 7
var max_rot_x_speed = 0
var max_rot_y_speed = 0
var move_camera = false # if true, the 3rd person camera will move arnd freely
var bullet = preload("res://18 3 red round.tscn")
var reload_time = 0.2
var reload_timer = 0
var fire_gun = false
func shoot():
var bullet_node = bullet.instance()
bullet_node.start(self)
get_parent().add_child(bullet_node)
# to keep track of what buttons are pressed
var pressed = {}
func is_action_just_pressed(action):
if Input.is_action_pressed(action):
if not pressed.has(action) or not pressed[action]:
pressed[action] = true
return true
else:
pressed[action] = false
return false
func _physics_process(delta):
# check if the deccelerate command is active
# if so, wait for the current rotation to finish
if retrograde and abs(rot_x_speed) < rot_acceleration * delta and abs(rot_y_speed) < rot_acceleration * delta:
# orders the ship to flip
rot_x_target = PI
retrograde = false
# IMPULSOR below
# constantly calculates the maximum rotational speed to reach the target orientation
if rot_x_target != 0:
max_rot_x_speed = sqrt(2 * abs(rot_x_target) * rot_acceleration) * abs(rot_x_target) / rot_x_target
if rot_y_target != 0:
max_rot_y_speed = sqrt(2 * abs(rot_y_target) * rot_acceleration) * abs(rot_y_target) / rot_y_target
# controls the speed in each axes to be equal to the max rotational speed
# if the difference is greater than the acceleration, a correction is made
if abs(max_rot_x_speed - rot_x_speed) > rot_acceleration * delta:
if rot_x_speed < max_rot_x_speed:
rot_x_speed += rot_acceleration * delta
elif rot_x_speed > max_rot_x_speed:
rot_x_speed -= rot_acceleration * delta
if abs(max_rot_y_speed - rot_y_speed) > rot_acceleration * delta:
if rot_y_speed < max_rot_y_speed:
rot_y_speed += rot_acceleration * delta
elif rot_y_speed > max_rot_y_speed:
rot_y_speed -= rot_acceleration * delta
rotate_object_local(Vector3(1, 0, 0), - rot_x_speed * delta)
rotate_object_local(Vector3(0, 1, 0), rot_y_speed * delta)
rot_x_target -= rot_x_speed * delta
rot_y_target -= rot_y_speed * delta
reload_timer += delta # for incrementing the reload timer
if reload_timer >= reload_time and fire_gun:
shoot()
reload_timer = 0
move_and_slide(velocity)
func _input(event):
if event.is_action("midmouse"):
move_camera = not move_camera
if event.is_action_pressed("retrograde"):
retrograde = true
if event.is_action("shoot"):
fire_gun = not fire_gun
if event is InputEventMouseMotion and not move_camera and not retrograde:
rot_x_target -= event.relative.y * mouse_sensitivity
rot_y_target -= event.relative.x * mouse_sensitivity
elif event.is_action("move_forward"):
velocity += get_global_transform().basis.z * acceleration
https://youtu.be/29ynaoqyM1k
is a vid of the game not working

Okay I found out that the scene was rotated 90 degrees on the x-axis for some reason
And that you can copy the global_transform directly

Related

The function 'connect()' returns a value, but this value is never used. What does this mean?

I am new to Godot, and I am creating my first project. There's something that annoys the heck out of me. It's this: "The function 'connect()' returns a value, but this value is never used." I don't know what to add to the line of code, but I will first show the code:
extends KinematicBody2D
var gravity = 1000
var velocity = Vector2.ZERO
var maxHorizontalSpeed = 120
var horizontalAcceleration = 100
var jumpSpeed = 320
var jumpTerminationMultiplier = 4
var hasDoubleJump = false
func _ready():
warning-ignore:return_value_discarded
$HazardArea.connect("area_entered", self, "on_hazard_area_entered")
func _process(delta):
var moveVector = Vector2.ZERO
moveVector.x = Input.get_action_strength("move_right") - Input.get_action_strength("move_left")
moveVector.y = -1 if Input.is_action_just_pressed("jump") else 0
velocity.x += moveVector.x * horizontalAcceleration * delta
if (moveVector.x == 0):
velocity.x = lerp(0, velocity.x, pow(2, -50))
velocity.x = clamp(velocity.x, -maxHorizontalSpeed, maxHorizontalSpeed)
if (moveVector.y < 0 && (is_on_floor() || $CoyoteTimer.is_stopped() || hasDoubleJump)):
velocity.y = moveVector.y * jumpSpeed
if(!is_on_floor() && $CoyoteTimer.is_stopped()):
hasDoubleJump = false
$CoyoteTimer.stop()
if(moveVector.y < 0 && !Input.is_action_just_pressed("jump")):
velocity.x = gravity * jumpTerminationMultiplier * delta
else:
velocity.y += gravity * delta
var wasOnFloor = is_on_floor()
velocity = move_and_slide(velocity, Vector2.UP)
if(wasOnFloor && !is_on_floor()):
$CoyoteTimer.start()
if(is_on_floor()):
hasDoubleJump = true
update_animation()
func get_movement_vector():
var moveVector = Vector2.ZERO
moveVector.x = Input.get_action_strength("move_right") - Input.get_action_strength("move_left")
moveVector.y = -1 if Input.is_action_just_pressed("jump") else 0
return moveVector
func update_animation():
var moveVec = get_movement_vector()
if(!is_on_floor()):
$AnimatedSprite.play("Jump")
elif(moveVec.x != 0):
$AnimatedSprite.play("Run")
else:
$AnimatedSprite.play("Idle")
$AnimatedSprite.flip_h = true if moveVec.x > 0 else false
func on_hazard_area_entered(_area2d):
print("die")
The problem is on line 13, and I would really appreciate some help!
there is not a solution for this problem. The only thinks you can do are these:
Or use the returning value (if you want)
Or press ignore in warning tab
This link can help you more https://godotengine.org/qa/78337/the-function-connect-returns-value-but-this-value-never-used

Godot 3: How to walk on walls using Gravity and Gravity Direction?

I want to make a 3D game on Godot with the player who can walk on walls and ceiling but I've tried to make this but it didn't work :(
This is the code of my Player First Person Controller:
extends KinematicBody
export var GravityDirection = Vector3(-9.8, 0, 0)
var held_object: Object
var velocity = Vector3.ZERO
var speed = 10
var MAX_SPEED = 30
var GravityStrength = 9.8
var throw_force: float = 200
var wall_one = Vector3(-9.8, 0, 0)
var wall_two = Vector3(0, 0, -9.8)
var wall_three = Vector3(9.8, 0, 0)
var wall_four = Vector3(0, 0, 9.8)
var ground = Vector3(0, -9.8, 0)
onready var ray = $"Camera/Hand/RayCast"
onready var hold_position = $"Camera/Hand/HoldPosition"
# Camera
onready var player_camera = $"Camera"
var spin = 0.1
export var mouse_sensitivity = 5
func _ready():
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
func _physics_process(delta):
var Gravity = GravityStrength * GravityDirection
var Velocity = Gravity * delta
move_and_collide(Velocity)
var run_once = 0
while 1:
if run_once == 0:
if GravityDirection == wall_one:
rotate_x(90)
run_once = 1
player_camera.rotation_degrees.y = 180
player_camera.rotation_degrees.z = 0
if Input.is_action_just_pressed("player_fire"):
fire()
if not is_on_floor():
Velocity.y += -GravityStrength
movement(delta)
velocity = move_and_slide(velocity, Vector3.ZERO)
if Input.is_action_just_pressed("player_pick"):
if held_object:
held_object.mode = RigidBody.MODE_RIGID
held_object.collision_mask = 1
held_object = null
else:
if ray.get_collider():
held_object = ray.get_collider()
held_object.mode = RigidBody.MODE_KINEMATIC
held_object.collision_mask = 0
if held_object:
held_object.global_transform.origin = hold_position.global_transform.origin
#_process_input()
#_process_gravity()
# Mouvement
func movement(_delta):
var dir = Vector3.ZERO
var vel_y = velocity.y
velocity = Vector3.ZERO
# Movement forward and backward
if Input.is_action_pressed("player_forward"):
dir += transform.basis.z
elif Input.is_action_pressed("player_backward"):
dir -= transform.basis.z
# Movement Left and Right
if Input.is_action_pressed("player_left"):
dir += transform.basis.x
elif Input.is_action_pressed("player_right"):
dir -= transform.basis.x
velocity = dir.normalized() * speed
velocity.y = vel_y
func _input(event):
if event is InputEventMouseMotion and Input.get_mouse_mode() == Input.MOUSE_MODE_CAPTURED:
rotate_y(lerp(0, -spin, event.relative.x * (mouse_sensitivity * 0.01) ))
player_camera.rotate_x(lerp(0,spin, event.relative.y * (mouse_sensitivity * 0.01)) )
#Clamp vertical rotation
var curr_rot = player_camera.rotation_degrees
curr_rot.x = clamp(curr_rot.x, -60, 60)
player_camera.rotation_degrees = curr_rot
func fire():
print("fire")
if ray.get_collider() != null and ray.get_collider().is_in_group("enemy"):
print(ray.get_collider())
ray.get_collider().hp -= 10
Nodes Configuration
In the code, you can find fonctions for the camera and gravity system. Also, there is a fonction to pick up rigid bodies. I want to make a system where when the Gravity has a specific direction, the mesh rotate to 90°. I've made a "GlobalRay" with 6 RayCast to detect collisions (walls) and register face blablabla... you've understood but I don't know how to make a system like this!!!
I think there is a way to optimize the script, so, I need help :D
If you can perform my code it's nice! Have a nice code!
It looks like you're subtracting GravityStrength from the player's y velocity if they are not on the floor, while you should be adding the Velocity to the player's velocity. Otherwise, this question here is very general and could be implemented in a lot of ways. wall_one, wall_two, wall_three etc. I think would be better off with a magnitude of one so they could undergo the same GravityStrength modifier as everything else in later implementations, but that's just me.

Why i am not able to make a projectile weapon using GDScript in Godot

I want to make a projectile weapon with GDScript but I am getting the error:
the function " _physics _process " already exists in this class (at line 35)
I cannot delete the line of code which has the error as if I do so I will not be able to make my FPS controller character move
here is the the code:
extends KinematicBody
var speed = 9
const ACCEL_DEFAULT = 7
const ACCEL_AIR = 1
onready var accel = ACCEL_DEFAULT
var gravity = 9.8
var jump = 4
var damage = 100
var cam_accel = 40
var mouse_sense = 0.1
var snap
var direction = Vector3()
var velocity = Vector3()
var gravity_vec = Vector3()
var movement = Vector3()
onready var head = $Head
onready var camera = $Head/Camera
onready var bullet = preload("res://player/world/bullet/bullet.tscn")
onready var muzzle = $Head/Gun/Muzzle
func _ready():
#hides the cursor
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
func _input(event):
if event is InputEventMouseMotion:
rotate_y(deg2rad(-event.relative.x * mouse_sensitivity))
head.rotate_x(deg2rad(-event.relative.y * mouse_sensitivity))
head.rotation.x = clamp(head.rotation.x, deg2rad(-90), deg2rad(90))
func _physics_process(delta):
direction = Vector3()
if Input.is_action_just_pressed("fire"):
if aimcast.is_colliding():
var b = bullet.instance()
muzzle.add_child(b)
b.look_at(aimcast.get_collision_point(), Vector3.UP)
b.shoot = true
func _process(delta):
#camera physics interpolation to reduce physics jitter on high refresh-rate monitors
if Engine.get_frames_per_second() > Engine.iterations_per_second:
camera.set_as_toplevel(true)
camera.global_transform.origin = camera.global_transform.origin.linear_interpolate(head.global_transform.origin, cam_accel * delta)
camera.rotation.y = rotation.y
camera.rotation.x = head.rotation.x
else:
camera.set_as_toplevel(false)
camera.global_transform = head.global_transform
# this is the line of code which is causing the error
(
func _physics_process(delta):
#get keyboard input
direction = Vector3.ZERO
var h_rot = global_transform.basis.get_euler().y
var f_input = Input.get_action_strength("move_backwards") - Input.get_action_strength("move_forward")
var h_input = Input.get_action_strength("move_right") - Input.get_action_strength("move_left")
direction = Vector3(h_input, 0, f_input).rotated(Vector3.UP, h_rot).normalized()
#jumping and gravity
if is_on_floor():
snap = -get_floor_normal()
accel = ACCEL_DEFAULT
gravity_vec = Vector3.ZERO
else:
snap = Vector3.DOWN
accel = ACCEL_AIR
gravity_vec += Vector3.DOWN * gravity * delta
if Input.is_action_just_pressed("jump") and is_on_floor():
snap = Vector3.ZERO
gravity_vec = Vector3.UP * jump
#make it move
velocity = velocity.linear_interpolate(direction * speed, accel * delta)
movement = velocity + gravity_vec
move_and_slide_with_snap(movement, snap, Vector3.UP) )
The error:
"_physics_process" already exists in this class
Is telling you that you have _physics_process twice in your script. You can only have one.
This is the first one:
func _physics_process(delta):
direction = Vector3()
if Input.is_action_just_pressed("fire"):
if aimcast.is_colliding():
var b = bullet.instance()
muzzle.add_child(b)
b.look_at(aimcast.get_collision_point(), Vector3.UP)
b.shoot = true
This is the second one:
func _physics_process(delta):
#get keyboard input
direction = Vector3.ZERO
var h_rot = global_transform.basis.get_euler().y
var f_input = Input.get_action_strength("move_backwards") - Input.get_action_strength("move_forward")
var h_input = Input.get_action_strength("move_right") - Input.get_action_strength("move_left")
direction = Vector3(h_input, 0, f_input).rotated(Vector3.UP, h_rot).normalized()
#jumping and gravity
if is_on_floor():
snap = -get_floor_normal()
accel = ACCEL_DEFAULT
gravity_vec = Vector3.ZERO
else:
snap = Vector3.DOWN
accel = ACCEL_AIR
gravity_vec += Vector3.DOWN * gravity * delta
if Input.is_action_just_pressed("jump") and is_on_floor():
snap = Vector3.ZERO
gravity_vec = Vector3.UP * jump
#make it move
velocity = velocity.linear_interpolate(direction * speed, accel * delta)
movement = velocity + gravity_vec
move_and_slide_with_snap(movement, snap, Vector3.UP)
I'm guessing you want both. So merge them into a single one with the code from both:
func _physics_process(delta):
direction = Vector3()
if Input.is_action_just_pressed("fire"):
if aimcast.is_colliding():
var b = bullet.instance()
muzzle.add_child(b)
b.look_at(aimcast.get_collision_point(), Vector3.UP)
b.shoot = true
#get keyboard input
direction = Vector3.ZERO
var h_rot = global_transform.basis.get_euler().y
var f_input = Input.get_action_strength("move_backwards") - Input.get_action_strength("move_forward")
var h_input = Input.get_action_strength("move_right") - Input.get_action_strength("move_left")
direction = Vector3(h_input, 0, f_input).rotated(Vector3.UP, h_rot).normalized()
#jumping and gravity
if is_on_floor():
snap = -get_floor_normal()
accel = ACCEL_DEFAULT
gravity_vec = Vector3.ZERO
else:
snap = Vector3.DOWN
accel = ACCEL_AIR
gravity_vec += Vector3.DOWN * gravity * delta
if Input.is_action_just_pressed("jump") and is_on_floor():
snap = Vector3.ZERO
gravity_vec = Vector3.UP * jump
#make it move
velocity = velocity.linear_interpolate(direction * speed, accel * delta)
movement = velocity + gravity_vec
move_and_slide_with_snap(movement, snap, Vector3.UP)
That should solve the error at hand. I haven't look deeper into the code for any other possible problems.

Godot player not walking in the direction

So I am new to godot and I was having a problem. The players body doesnt follow the camera when the camera moves When I look around with the camera the players body stays the same e.g. if i use wasd if i turn to the right it would be aswd. the player movement is hard but i got help. if you could help that will be super cool, i am just trying to learn coding. this is hard for me.
p.s sorry for the bad grammar
extends KinematicBody
signal hit
# How fast the player moves in meters per second.
export var speed = 14
# The downward acceleration when in the air, in meters per second squared.
export var fall_acceleration = 50
# Vertical impulse applied to the character upon jumping in meters per second.
export var jump_impulse = 30
# Vertical impulse applied to the character upon bouncing over a mob in meters per second.
export var bounce_impulse = 16
# stats
var curHP : int = 10
var maxHP : int = 10
var ammo : int = 15
var score : int = 0
# cam look
var minLookAngle : float = -90.0
var maxLookAngle : float = 90.0
var lookSensitivity : float = 10.0
# vectors
var vel : Vector3 = Vector3()
var mouseDelta : Vector2 = Vector2()
# components
onready var camera : Camera = get_node("Camera")
onready var muzzle : Spatial = get_node("Camera/Muzzle")
# Emitted when a mob hit the player.
var velocity = Vector3.ZERO
func _physics_process(delta):
var direction = Vector3.ZERO
if Input.is_action_pressed("move_right"):
direction.x += 1
if Input.is_action_pressed("move_left"):
direction.x -= 1
if Input.is_action_pressed("move_back"):
direction.z += 1
if Input.is_action_pressed("move_forward"):
direction.z -= 1
#sprinting
if Input.is_action_pressed("move_sprint"):
speed = 50
if Input.is_action_just_released("move_sprint"):
speed = 14
velocity.x = direction.x * speed
velocity.z = direction.z * speed
# Jumping.
if is_on_floor() and Input.is_action_just_pressed("move_jump"):
velocity.y += jump_impulse
velocity.y -= fall_acceleration * delta
velocity = move_and_slide(velocity, Vector3.UP)
func _ready():
# hide and lock the mouse cursor
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
func _process(delta):
# rotate the camera along the x axis
camera.rotation_degrees.x -= mouseDelta.y * lookSensitivity * delta
# clamp camera x rotation axis
camera.rotation_degrees.x = clamp(camera.rotation_degrees.x, minLookAngle, maxLookAngle)
# rotate the player along their y-axis
rotation_degrees.y -= mouseDelta.x * lookSensitivity * delta
# reset the mouseDelta vector
mouseDelta = Vector2()
func _input(event):
if event is InputEventMouseMotion:
mouseDelta = event.relative
If you want the movement to be based on the orientation of camera...
Then base the movement:
var direction = Vector3.ZERO
if Input.is_action_pressed("move_right"):
direction.x += 1
if Input.is_action_pressed("move_left"):
direction.x -= 1
if Input.is_action_pressed("move_back"):
direction.z += 1
if Input.is_action_pressed("move_forward"):
direction.z -= 1
On the orientation of the camera.
We will use camera.global_transform.basis. The basis of a transform gives us a set of vectors that are aligned to the axis of the transformed space.
Using camera.transform instead of camera.global_transform will NOT work, because the Camera is a child of the KinematicBody.
Then your code ends up like this:
var direction = Vector3.ZERO
var camera_x = camera.global_transform.basis.x
var camera_z = camera.global_transform.basis.z
if Input.is_action_pressed("move_right"):
direction += camera_x
if Input.is_action_pressed("move_left"):
direction -= camera_x
if Input.is_action_pressed("move_back"):
direction += camera_z
if Input.is_action_pressed("move_forward"):
direction -= camera_z
Complete script on OP request:
extends KinematicBody
#signal hit
# How fast the player moves in meters per second.
export var speed = 14
# The downward acceleration when in the air, in meters per second squared.
export var fall_acceleration = 50
# Vertical impulse applied to the character upon jumping in meters per second.
export var jump_impulse = 30
# Vertical impulse applied to the character upon bouncing over a mob in meters per second.
# export var bounce_impulse = 16
# stats
# var curHP : int = 10
# var maxHP : int = 10
# var ammo : int = 15
# var score : int = 0
# cam look
var minLookAngle : float = -90.0
var maxLookAngle : float = 90.0
var lookSensitivity : float = 10.0
# vectors
# var vel : Vector3 = Vector3()
var mouseDelta : Vector2 = Vector2()
# components
onready var camera : Camera = get_node("Camera")
# onready var muzzle : Spatial = get_node("Camera/Muzzle")
# Emitted when a mob hit the player.
var velocity = Vector3.ZERO
func _physics_process(delta):
var direction = Vector3.ZERO
var camera_x = camera.global_transform.basis.x
var camera_z = camera.global_transform.basis.z
if Input.is_action_pressed("move_right"):
direction += camera_x
if Input.is_action_pressed("move_left"):
direction -= camera_x
if Input.is_action_pressed("move_back"):
direction += camera_z
if Input.is_action_pressed("move_forward"):
direction -= camera_z
#sprinting
if Input.is_action_pressed("move_sprint"):
speed = 50
if Input.is_action_just_released("move_sprint"):
speed = 14
velocity.x = direction.x * speed
velocity.z = direction.z * speed
# Jumping.
if is_on_floor() and Input.is_action_just_pressed("move_jump"):
velocity.y += jump_impulse
velocity.y -= fall_acceleration * delta
velocity = move_and_slide(velocity, Vector3.UP)
func _ready():
# hide and lock the mouse cursor
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
func _process(delta):
# rotate the camera along the x axis
camera.rotation_degrees.x -= mouseDelta.y * lookSensitivity * delta
# clamp camera x rotation axis
camera.rotation_degrees.x = clamp(camera.rotation_degrees.x, minLookAngle, maxLookAngle)
# rotate the player along their y-axis
rotation_degrees.y -= mouseDelta.x * lookSensitivity * delta
# reset the mouseDelta vector
mouseDelta = Vector2()
func _input(event):
if event is InputEventMouseMotion:
mouseDelta = event.relative

How do I write a code that controls jumps, and creates a double jump action'?

# changed switch statement setup by creating a new variable and using "." operator
# removed extra delta in move_and_slide function
# left off attempting to add gravity to the game
# 2/26/2019
# removed FSM and will replace it with tutorial video code, for sake of completion
extends Node2D
const FLOOR = Vector2(0,-1)
const GRAVITY = 5
const DESCEND = 0.6
var speed = 100
var jump_height = -250
var motion = Vector2()
var jump_count = 0
var currentState = PlayerStates.STATE_RUNNING
var grounded = false
enum PlayerStates {STATE_RUNNING, STATE_JUMPING, STATE_DOUBLE_JUMPING, STATE_GLIDING}
func _ready():
var currentState = PlayerStates.STATE_RUNNING
pass
func jump():
motion.y = jump_height
func glide():
if motion.y < 500:
motion.y += DESCEND
func _process(delta):
var jump_pressed = Input.is_action_pressed('jump')
var glide_pressed = Input.is_action_pressed('glide')
* the code below is where I attempted to count the jumps in order to keep them from surpassing two jumps. My goal is to create a double
jump and so I used the less than operator to control that number*
if jump_pressed:
if jump_count < 2:
jump_count += 1
jump()
grounded = false <-- I had to copy paste this code again, below, so I don't get an error in my question.
if jump_pressed:
if jump_count < 2:
jump_count += 1
jump()
grounded = false
if grounded == false:
if glide_pressed:
glide()
motion.x = speed
motion.y += GRAVITY
motion = move_and_slide(motion, FLOOR)
if is_on_floor():
grounded = true
jump_count = 0
else:
grounded = false
First of all, I think you need to use a KinematicBody2D and perform your logic in _physics_process if you would like to use move_and_slide, other than that, your code was almost working:
extends KinematicBody2D
const FLOOR = Vector2(0,-1)
const GRAVITY = 3000
const DESCEND = 0.6
var speed = 100
var jump_height = 250
var motion = Vector2()
var jump_count = 0
func jump():
motion.y = -jump_height
func glide():
if motion.y < 500:
motion.y += DESCEND
func _physics_process(delta):
var jump_pressed = Input.is_action_pressed('jump')
var glide_pressed = Input.is_action_pressed('glide')
motion.y += delta * GRAVITY
var target_speed = Vector2(speed, motion.y)
if is_on_floor():
jump_count = 0
if glide_pressed:
glide()
if jump_pressed and jump_count < 2:
jump_count += 1
jump()
motion = lerp(motion, target_speed, 0.1)
motion = move_and_slide(motion, FLOOR)
You also need to change the node type to KinematicBody2D in the Godot editor (right click on the node and then on change type).

Resources