Make KinematicBody2D Fly

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By checharor

I’ve my charecter in the ground and everything works perfect, i’m wondering how can i make it “Ignore Gravity” so he can fly when i press a key, here’s my code:

extends KinematicBody2D

const SPEED = 170
const GRAVITY = 10
const JUMP = -400
const FLOOR = Vector2(0, -1)
var velocity = Vector2()
var on_floor = false

func _physics_process(delta):
velocity.y += GRAVITY

Thnx a lot

:bust_in_silhouette: Reply From: deaton64

Either, change gravity to a var and set it to 0 when flying.


Have a flying bool and do something like:

if !flying:
	velocity.y += GRAVITY

Thnx what a simple solution

checharor | 2020-06-06 19:42