Hi, I finished one of the 2d video tutorials and now I’m playing around on my own. My current goal is to be able to move some colored balls into the center once I’ve touched them with the UFO. I move the UFO with a joystick. The balls spawn on the screen with random positioning and velocity, I’ve made them dynamic rigidbodies2d so they can bounce of the walls. Once I touch them with the ufo, the idea is to be able to carry them. I did it like this (balls are tagged as Stone1, 2 etc.)
private void OnCollisionEnter2D(Collision2D other)
{
if (other.gameObject.tag.ToString()=="Stone1")
{
other.gameObject.GetComponent<Rigidbody2D>().isKinematic = true;
other.gameObject.transform.SetParent(transform,true);
Debug.Log("Touched Stone1");
}
}
This somewhat works since it makes the ball stick to the UFO, but after moving it with the joystick the ufo starts rotating for some reasong, which makes movement erratic.
Thanks
That’s weird, if they’re set to kinematic they shouldn’t be interfering with the UFO. How is the UFO gameobject setup and how do you move it?
1 Like
Here is the code for UFO (PlayerController), at start I do this:
rb2d = GetComponent();
and then in Fixed Update
private void FixedUpdate() // with joystick
{
horizontalMove = FixedJoystick.Horizontal * speed;
verticalMove = FixedJoystick.Vertical * speed;
Vector2 movement = new Vector2(horizontalMove, verticalMove);
// rb2d.AddForce(movement);
rb2d.velocity = movement;
}
commenting out the line that makes Stones kinematic does not appear to make a difference

Weird!
Maybe try setting simulated to false instead of turning kinematic on, that should disable all physics interactions:
other.gameObject.GetComponent<Rigidbody2D>().simulated = false;
It’s also possible the centerOfMass of your UFO is changing after parenting, so try resetting that to 0,0 after parenting the ball as well if the above doesn’t work.
1 Like
So first I tried setting the simulation off, which made the rotation more stable (always counter clockwise). Then I tried
rb2d.fixedAngle = true
and this combination seems to work! The rotation is gone. One thing that is weird is that if I comment setting the simulation to false like this
//other.gameObject.GetComponent<Rigidbody2D>().simulated = false;
other.gameObject.transform.SetParent(transform,true);
rb2d.fixedAngle = true;
the ball bounces off the UFO and does not stick.
So at this point now my goal is to make the balls disappear once they reach the sink in the center. This is my sink script:```
private void OnCollisionEnter2D(Collision2D other)
{
//Color myColor = gameObject.GetComponent().color;
//Color otherColor = other.gameObject.GetComponent().color;
Debug.Log("Sink Collision Detected with " + other.gameObject.tag.ToString());
// Debug.Log( "myColor is " + myColor.ToString() );
//Debug.Log("Ball is " + otherColor.ToString());
if (other.gameObject.tag.ToString() == “Stone1”)
{
// other.gameObject.transform.parent = null;
other.gameObject.SetActive(false);
Debug.Log(“Color Match”);
}
}
However, the sink collision with the ball is not getting detected, but it does detect collisions with the ufo??
Thanks!


Oh, it’s because setting the simulation to false will do deactivate the colliders…