How to make object attach to another object after collision? [SOLVED]

Hi, I am making a game about throwing a spear to the shield. After Collision, the spear will attach to the shield. I already create this game in unity and I want to re-create it again in defold.

I struggle to make the spear attached to the shield. I already use 2 different ways to do that, it still didn’t work.

First , using go.set_parent(go.get_id(), go.get_id('/Shield')) and the output will look like this.

Second, using weld joint
physics.create_joint(physics.JOINT_TYPE_WELD, "/Shield#collisionobject", "my_test_joint", vmath.vector3(0, 0, 0), "/Spear#collisionobject", vmath.vector3(0, 350, 0), { collide_connected = true })

In a second way, maybe it looks works but it only attaches to a specific location, not in the location where 2 objects colliding

What type of collision object is the shield? Trigger, kinematic, dynamic or static?.. How do you rotate it?

I use kinematic collision on the shield.
the syntax to spin the shield

local rotation = go.get_rotation(object)
rotation = rotation * vmath.quat_rotation_z(0.0025)
go.set_rotation(rotation, object)

Hey I followed your code.
I think the only thing missing is the
the third parameter of go.set_parent (keep world transform):

just set to true and worked here:

remember to disable the collision after the hit.

4 Likes

Thanks for the suggestion, it works. I didn’t notice go.set_parent() has third parameter.

2 Likes