Moving colliders that are part of a composite collider

So I’ve been working on this game for the past few days. It’s a 2D puzzle where you have to align multiple cursors in a certain way so they’ll press all the buttons on the screen at the same time.

I uploaded a video of what I’ve come up with, but there are still a lot of things to change.
Mainly, one thing that I’m really struggling with is the moving cursors, which are shown 33 seconds into the video. They’re not really buggy at all, and they work perfectly for the first few levels, but they don’t work at all with the obstacles, which are shown 50 seconds into the video.

This is because the way the cursors (and buttons) move in the game is through setting transform.localPosition instead of using the Unity physics engine, which is what a still cursor does.

I’ve been trying to get the moving cursors to work through velocity with so far no success. The cursors don’t have a Rigidbody. Instead they are children of the main cursor, which has a Rigidbody and a Composite Collider. All the extra cursors (and the main cursor too) have a Box Collider, which is automatically part of the Composite Collider.

Is there any way to get this to work?

EDIT: One idea I had is to save the moving cursor’s current position, give the main cursor velocity backwards, reset the moving cursor’s position, then give the main cursor the same velocity forwards. This would work perfectly, however the velocity is only applied after a physics update, meaning that I can’t all do it in one run. I could make each action happen in a different physics update, but then the cursors would be jittering constantly. Is there perhaps a way to apply velocity immediately?

I figured it out eventually by using raycasting to simulate velocity. I created this function:

``````RaycastHit2D simulatedVelocity(Transform t, Vector2 direction, float distance) {

RaycastHit2D rc = Physics2D.Raycast ((Vector2)t.position, direction, Mathf.Infinity, layerMask);

if (rc.distance > distance)
rc.distance = distance;

return rc;
}
``````

in order to simulate velocity. It’s essentially the same as setting the velocity or using AddForce, but you can get the resulting position without having to wait for the physics to update.