StaticBody2D not colliding with kinematic2D

Attention Topic was automatically imported from the old Question2Answer platform.

I am new to godot and i am trying to make a platformer game but i am facing an issue i have a scene that look likes this

and i have a script attached to the player

``````extends KinematicBody2D
var gravity = 100

# Declare member variables here. Examples:
# var a = 2
# var b = "text"

# Called when the node enters the scene tree for the first time.
pass # Replace with function body.
func _physics_process(delta):
position.y += gravity * delta
# Called every frame. 'delta' is the elapsed time since the previous frame.
#func _process(delta):
#	pass
``````

the player is going down but it isn’t colliding with the invisible platform
can any one help me?

You are directly changing the player’s position, but a KinematicBody has move_and_slide() for collisions.

You basically need a velocity variable

``````var velocity : = Vector2(0, 0)
``````

Change the velocity

``````velocity.y += gravity * delta
``````

And then use move_and_slide() to move

``````velocity = move_and_slide(velocity)
``````

And if I’m correct this should work:

``````func _process(delta):
velocity.y += gravity * delta
velocity = move_and_slide(velocity)
``````

Thank you very much sir but the player still isn’t moving at all

``````extends KinematicBody2D
var gravity = 100
var velocity : = Vector2(0, 0)
# Declare member variables here. Examples:
# var a = 2
# var b = "text"

# Called when the node enters the scene tree for the first time.
pass # Replace with function body.
func _process(delta):
velocity.y += gravity * delta
velocity = move_and_slide(velocity)
# Called every frame. 'delta' is the elapsed time since the previous frame.
#func _process(delta):
#	pass
``````

NT_Virus | 2023-02-27 10:20

Trying your code myself the player does fall.
Are you 100% sure the KinematicBody, the collision shape and the sprite are all at the same position? If not, reset the transform of all and move the kinematicBody using the move tool (not the select tool).

Jayden13O | 2023-02-27 13:20