RigidBody2D like Gravity or motion on KinematicBody2D

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

I am a beginner to Godot. I am creating a simple game to learn Godot in which I am using a KinematicBody2D as my player. Now my question is when I use KinematicBody2D
something like this happens with my box when it comes on the corner


but I want it to behave like a rigidbody2d like this


It has a simple controlling script

extends KinematicBody2D
const Gravity = 30
const Move = 500
var motion = Vector2()
var jump = 700
var up = Vector2(0,-1)
var canJump = true

func _ready():

func _physics_process(delta):
	motion.y += Gravity
	if Input.is_action_pressed("ui_right") :
		motion.x = Move
	elif Input.is_action_pressed("ui_left"):
		motion.x = -Move
	else :
		motion.x = 0
	if is_on_floor():
		canJump = true
	if Input.is_action_pressed("ui_up"):
		if canJump:
			motion.y = -jump
			canJump = false
	motion = move_and_slide(motion)

I would like to know is there a way so that I can make It work like in the image-2

I know little about those nodes. But can’t you change the type of node on the fly? In other words, change a RigidBody2D to a KinematicBody2D when necessary?

Ertain | 2018-08-23 20:13

Of course, you can, by changing RigidBody2D.mode or even in the inspector.

Dlean Jeans | 2018-08-24 02:08