Using joints in my player collection

I’m building a 2d-top down shooter.

I’m playing with the idea of connecting the gun to the body with joints. The gun would be connected to a lower arm, which is connected to an upper arm, which is connected to the body. So ideally some physics-based elbow/shoulder movement could occur.

My first question: is this even possible with a game that isn’t using physics elsewhere?

My player collection looks like this (I haven’t added “upper arm yet”):

I try to attach the gun to the lower arm with this code:

physics.create_joint(physics.JOINT_TYPE_FIXED, "playerWeapon#collisionobject", "my_test_joint", vmath.vector3(0, 0, 0), "playerLowerArm#collisionobject", vmath.vector3(0, 0, 0), { max_length = 0 })

The arm doesn’t seem to move with the gun.

My gun GO has a kinematic collisionobject. The gun GO moves around programmatically (from mouse cursor input).

My lower-arm GO I’ve tried with dynamic and kinematic.

I would like to see the lower-arm move with the gun.

Thanks!

1 Like

This is totally doable using joints. You could also use Spine or Rive models to achieve the same thing or better. Here’s an example using physics joints:

3 Likes

Thank you @britzl this example is exactly what I needed!

1 Like