0 votes

Hello,

Can somebody please tell me, how could i manipulate a RigidBody2D with a KinematicBody2D character correcty? Like a character picking up a box and carry.
I made my character to pick up the box, but the KinematicBody2D ignores the RigidBody2Ds collisions, and pushes it into walls like TileMaps etc... (The RigidBody2D is colliding with the TileMap when its not picked)
I would like to get some "force feedback" from the RigidBody2D to let the KinematicBody2D to know that he cannot go any further.

My code for picking up the BOX:

extends Area2D

onready var boxgroup = getnode('/root/World/Boxes')
onready var player = get_parent()

var picked = false
var body = null
var offset = Vector2(0, 17)

func physicsprocess(delta):

if Input.is_action_just_pressed("ui_page_up"):
    var colliders = get_overlapping_bodies()
    for box in colliders:
        if box.is_in_group('box'):
            body = box
            box_group.remove_child(body)
            player.add_child(body)
            body.position = offset
            picked = true

if picked == true:
    body.rotation = false
    body.sleeping = true

if Input.is_action_just_pressed("ui_page_down"):
    var body_position = body.global_position
    if picked == true:
        picked = false
        body.sleeping = false
        player.remove_child(body)
        box_group.add_child(body)
        body.apply_central_impulse(Vector2(Global.drone_velocity, Global.drone_y_velocity / 1.5))
        body.set_position(body_position) 

I tried without reparenting the box to the player, but it doesen`t work that way either.

Thanks

in Engine by (26 points)

Please log in or register to answer this question.

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.