0 votes

So right now, I'm trying to set something up where when the character (KinematicBody2D, CollisionShape2D as child) collides with another KB2D/CS2D, the non-character collision object (the box) physically sticks to the character, like so: https://i.imgur.com/7Bu9Rv6.mp4

But as you can see, at certain approach angles, the box goes to the flip side of the character (and even has the correct spacing).

Along with this, the collisions aren't always perfect either https://i.imgur.com/wEztHEq.mp4

Sorry that my video isn't great, but there's a bit of a gap between the two boxes, when I want it to be flush. There'll also be times when the box will be further into the character (like a negative gap, the phrase escapes me right now), which I can't understand.

func reparent(node, poc):
    print(poc - self.position)
    var loc = poc - self.position 
    node.get_parent().remove_child(node)
    self.add_child(node)
    node.set_position(loc.rotated(rotation))

func _physics_process(delta):
    get_input()
    rotation = rotation_speed * delta * rotation_dir
    velocity = move_and_collide(velocity * delta)
    if velocity:
        call_deferred("reparent", velocity.collider.get_child(0), velocity.collider.position)      

This is what I'm currently using for the reparenting the child CS2D from it's own entity to the character.

I'd appreciate any and all advice! Cheers

asked Jun 19, 2019 in Engine by mikemountain (19 points)

1 Answer

0 votes
Best answer

I'm stupid, I changed a ton of things but the major difference was using

get_global_position()

d'oh.

answered Jun 22, 2019 by mikemountain (19 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.