- Home /
Pulling multiple objects
Since I am not getting responses, even requests for clarification, I guess I did a bad job asking the question. Any help, even a request to clarify would be greatly appreciated. For background I am doing this abacus to help out a friend who is doing his Masters in Education. I also wanted a project that I could learn Unity with. This simple app seemed like a great place to start.
I am attempting to create an abacus. I have a script that will drag a bead around just nicely. When the bead that I am dragging around comes into contact with another bead they both move but at a snails pace. How do I get the combined beads to continue to move at the same speed as a single bead?
I am using RigidBody2D, and BoxCollider2D along with a SliderJoint2D on each of the beads. The SliderJoint2D starts off not having a Connected Rigid Body.
Here is the movement script that I have been using.
using UnityEngine;
using System.Collections;
public class DragBead2 : MonoBehaviour {
private SliderJoint2D slider;
void Awake()
{
// "slider" is the SliderJoint2D component that I added to my object
slider = this.gameObject.GetComponent<SliderJoint2D>();
// I want the anchor position to start at the object's position
slider.connectedAnchor = gameObject.transform.position;
}
void OnMouseDown()
{
// I'm reactivating the SliderJoint2D component each time I'm clicking on my object
// because I'm disabling it after I'm releasing the mouse click so it will fly in
// the direction i was moving my mouse
slider.enabled = true;
}
void OnMouseDrag()
{
if (slider.enabled == true)
{
// Getting cursor position
Vector2 cursorPosition = Camera.main.ScreenToWorldPoint (Input.mousePosition);
// The anchor get's cursor's position
slider.connectedAnchor = cursorPosition;
}
}
void OnMouseUp()
{
// Disabling the slider component
slider.enabled = false;
}
}
Any help is greatly appreciated. As a side note this script is a modified version of a script I found on here (sorry but I cannot remember whose it was originally).
Thanks in advance.
In addition to using SliderJoint2D, I have tried SpringJoint2D and DistanceJoint2D all of which result in similar behavior. The collision detection on the RigidBody2D is set to Continuous and Interpolated. I noticed that moving multiple beads with collision detection set to Discrete is a little better (they move faster), but at this point the collision detection no longer respects the bead boundries and the beads can be forced to overlap and even go through one another. Some background: The Soroban abacus that I am trying to model has 4 beads below the count bar on the bottom. If I grab the top bead, the movement is fine, I can move it up and down without issue. If I was to grab the second bead from the top and move it up, push the top bead at the same time, the movement slows down to a crawl. If I was to grab the third bead from the top and move it up, pushing to other two beads up, the movement is even slower. Pushing all four beads up, by grabbing the bottom bead, is not even possible, they just dont move.
I'm not too familiar with this aspect of the API, but if you are using physics to move the beads, they might be too heavy (check the mass of the rigidbodies)?
That being said, it might be easier to manipulate transforms directly, and not use the physics system at all.
Your answer
![](https://koobas.hobune.stream/wayback/20220613175714im_/https://answers.unity.com/themes/thub/images/avi.jpg)