0 votes

Hi everyone! I have a problem with a RigidBody2D mobile platform. When I jump on it with my KinematicBody2D player, the above platform flips and goes adrifts. How can I design a rigid mobile platform? Thank you!

asked Feb 8, 2019 in Engine by Rob1980 (70 points)

You may need to post some code or a link to your project

Ok, this is the platform code:

extends RigidBody2D

func _integrate_forces(state):
    if position.y >= 480:
        linear_velocity = linear_velocity * (-1)
    elif position.y <= 80:
        linear_velocity = linear_velocity * (-1)

And this is the player code:

extends KinematicBody2D

signal addScore

const FLOOR = Vector2(0, -1)
var motion = Vector2()
var on_ground = false

func _physics_process(delta):
    motion.y += 10
    move_and_slide(motion)
    if Input.is_action_pressed("ui_right"):
        $AnimatedSprite.set_flip_h(false)
        motion.x = 300
        move_and_slide(motion)
    elif Input.is_action_pressed("ui_left"):
        $AnimatedSprite.set_flip_h(true)
        motion.x = -300
        move_and_slide(motion)

    if Input.is_action_pressed("ui_up"):
        $Jump.play()
        if on_ground == true:
            motion.y = -300
            on_ground = false
        motion = move_and_slide(motion, FLOOR)
    if is_on_floor():
        on_ground = true
    else:
        on_ground = false
    position.y = clamp(position.y, -256, 1600)
    if position.y >= 1500:
        $wrong.play()
        position.x = 900
        position.y = 100

1 Answer

0 votes
Best answer

I solved my problem using a KinematicBody2D platform instead of a RigidBody2D one.

answered Feb 10, 2019 by Rob1980 (70 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.