–1 vote

Hey everybody!

The game is in 2d.
There's a player and bunch of other objects for the player to grab.
I want to make the player grabbing the objects then move along with them and the player can also rotate as empty handed(rotate in the same grid).
Meanwhile keep their collision shapes.

Here's the problem:
If I make the objects children of the player, their collisions stop working, because the player can only use his own collisionshape.
If I make the objects children of the player and add the collisions of the objects to player's collision,the origin of the player will change and mess up its rotating because the game is grid based.
If I use joint to combine them, they will rotate individually, which is not what I need.

I'm totally new to coding and Godot engine, so sorry if this is a basic problem and thanks a lot for anyone who provides any help!

Godot version 3.5.1
in Engine by (55 points)
edited by

1 Answer

+1 vote

Our project is 3D but the same process might apply:

1.) Instead of adding the dragging objects as children of the player, translate the object WITH the player in a _physics_process(delta) function. Reference the player node using get_node().
2.) Rotate the object by using the player's rotation in this function.
3.) However, the object will be glitched inside the player if you do not call add_collision_exception_with(DraggingObject) on the player.

If you still want the player to collide with the dragging object, use a dummy marker node's global transform as the reference point for where you want the object and add that dummy node as a child of the player. Use to_global(transform) on the dummy node to find the global transform (translation + rotation) for the dragging object.

This should place your dragging object in the correct position without all the node inheritance bullshit. I hope this works for you.

by (137 points)
edited by

The dummy works really well, and I solved another problem with this adorable dummy!
Thank you so much !!!!!

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.