This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
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!

in Engine by (96 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.

by (96 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 Frequently asked questions and 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 [email protected] with your username.