- Home /
My Instantiated object is affected by the original one
Hello everyone, I'm making a simple block breaker game like Arkanoid everything is perfect except that In my game I've a magic block which duplicates the ball into 2 balls I've used Instantiate() method, it worked perfectly but I had a problem, which when I hit the original ball with the striker the Instantiated ball is also affected by the collision of the original ball with the striker, but not vise versa I don't know why,but that's weird.
my instantiate ball code:
public void duplicateBalls()
{
float xPos = this.transform.position.x;
float yPos = this.transform.position.y;
var ballClone= Instantiate (GameObject.FindObjectOfType<BallMovementManager> (),new Vector3(xPos,yPos,0f),Quaternion.identity);
ballClone.GetComponent<Rigidbody2D> ().velocity=new Vector2(3,10f);
ballClone.tag = "Clone Ball"; //changing the tag of the clone ball in order to destroy it later
ballsCount++; //incrementing the total number of balls in the game
}
+My ball has a rididbody2D and a circular collider +My striker has only a box collider
thanks in advance.
Answer by as30050273 · Aug 13, 2017 at 09:03 AM
Hello! I think you need instantiate it with changing it's X cord a bit. Like that:
GameObject ballObj = GameObject.FindObjectOfType<BallMovementManager>();
//fill that with half of the width of your ball
float xOffset = 1f;
GameObject ballClone = Instantiate (ballObj, new Vector3(xPos + xOffset, yPos, 0f), Quaternion.identity) as GameObject;
the same problem stills idk if you knew what I meant suppose that the original ball is colliding with the striker and the clone ball is at the middle of the screen then the two balls would be affected by the collision and they will go up.
that would not be efficient ! the ball must collides the striker not triggering it
Could you give a screenshot? I think I dont understand you
Your answer
Follow this Question
Related Questions
how do I enable collision? 0 Answers
Tilemap Collider 2D preventing objects from moving 2 Answers
How do I get collisions between Tilemap Collider 2d and a Kinematic Rigidbody 2d? 1 Answer
How do I stop characters from standing on top of each other 1 Answer
How do I create a partial 2D sprite collision during trigger? 1 Answer