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
    if Input.is_action_pressed("ui_right"):
        motion.x = 300
    elif Input.is_action_pressed("ui_left"):
        motion.x = -300

    if Input.is_action_pressed("ui_up"):
        if on_ground == true:
            motion.y = -300
            on_ground = false
        motion = move_and_slide(motion, FLOOR)
    if is_on_floor():
        on_ground = true
        on_ground = false
    position.y = clamp(position.y, -256, 1600)
    if position.y >= 1500:
        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.