0 votes

I made a moving platform which is kinematicbody2d and when a player (which is a kinematicbody2d too) stands on it moving platform is going down. I don't know why.

Moving platform script:

   extends KinematicBody2D

var velocity = Vector2.ZERO
var x_direction = 1
var x_speed = 30
var y_speed = 1
var y_direction = 1

func _physics_process(delta):

    #X

    velocity.x = x_speed * x_direction
    var collision = move_and_collide(velocity * delta)
    if collision != null and collision.collider.is_in_group("Ground"):
        if x_direction == 1:
            x_direction = -1
        elif x_direction == -1:
            x_direction = 1


    #Y

    velocity.y = y_speed * y_direction



func _on_Timer_timeout():
    y_direction = -1

func _on_Timer2_timeout():
    y_direction = 1
in Engine by (16 points)

did you make collision shape for the platform?

Yes i did make a collision shape.

i think you shouldnt make the platform with kinematicbody2d use instead staticbody2d or if you have tileset make tilemap

1 Answer

0 votes

What is it that you want to do with this platform though ? If you just want it to move around x-axis then simply do this change

var y_speed = 0

the platform will not go down if the player is standing on top of it now.

by (270 points)
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.

Categories