Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Ati97 |
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 box_group = get_node(‘/root/World/Boxes’)
onready var player = get_parent()
var picked = false
var body = null
var offset = Vector2(0, 17)
func _physics_process(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