0 votes

i have kinematic body i want i want to move it but if i use moveandslide or moveandcollide there is a gravity how how can i remove the gravity

in Engine by (42 points)

usually you define the vector for moveandfoobar yourself. Can you show us your code? (Whole function/method)

1 Answer

0 votes
Best answer

"Kinematic bodies are special types of bodies that are meant to be user-controlled. They are not affected by physics at all" (Source) If there is gravity, it is there because you added it! As you haven't provided any code, this will be the answer for now.

by (10,153 points)
selected by

here is my code

extends KinematicBody2D
var velocity = Vector2(0, 0 )
var speed = 750
signal shoot
signal  shoot_realsed
func _physics_process(delta):
    if Input.is_action_pressed("droite"):
        velocity.x = 5 * -speed 
    elif Input.is_action_pressed("gauche"):
        velocity.x = 5 * speed 
    elif Input.is_action_pressed("ui_up"):
        velocity.y = 5 * speed
    elif Input.is_action_pressed("shoot"):
    elif Input.is_action_just_released("shoot"):

And what exactly do you perceive as gravity here?

  • If you press any key associated with the InputAction called "droite", the player's velocity in x-direction is set to 5 * -750 = -3750, so the player will move to the left (which feels a bit weird, given that "droite" means "right" in french).
  • If you don't press any key associated with "droite", the script will go on and check if you press any key associated with "gauche" and if that's the case, the player will move to the right with a velocity of 3750 in x-direction.
  • If you don't press any key associated with neither "droite" nor "gauche", but a key associated with "ui_up" the player's velocity is set to 3750 in y-direction. The positive y-direction is pointing downwards, so the player will "fall". That's not gravity though, but a misunderstanding on your side at most.

You don't reset the velocity back to zero when none of these keys are pressed, which may or may not be intended. Also you're not multiplying the velocity with delta, so your character will move extremely fast on high FPS and slower on lower FPS.

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 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 webmaster@godotengine.org with your username.