- Home /
Question by
SunilPandey__ · Oct 08, 2013 at 11:27 AM ·
platfrom
Instantiating platform problem
In my 2d game I have to make infinite platform. three types of platform will be used. When I am Instantiating platforms after some time they collide with each other. is three any other way to create infinite platform or better way. here is my code
public void SpawnPlatform ()
{
delta += Time.deltaTime;
if (delta - time > 6) {
platform.Add ((GameObject)Instantiate (platformPrefab, new Vector3 (transform.position.x * (-(i)), transform.position.y, transform.position.z), transform.rotation));
time = delta;
}
Comment
Answer by robertbu · Oct 08, 2013 at 04:29 PM
How about keeping track of the previous platform, and using Physics.IgnoreCollision() to keep the two platforms from colliding. Here is a bit of untested code to give you the idea:
GameObject go = Instantiate (platformPrefab, new Vector3 (transform.position.x * (-(i)), transform.position.y, transform.position.z), transform.rotation) as GameObject;
if (platform.Count > 0) {
Physics.IgnoreCollision(platform[Platform.Count-1].collider, go.collider);
}
platform.Add(go);
Your answer
![](https://koobas.hobune.stream/wayback/20220613115528im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
rigidbody2D.velocity.y always returns 0 2 Answers
GL Lines With Textures 1 Answer
Draw outline around 2D shape 1 Answer
Move infinitely in targeted direction 3 Answers
Removing elements of list 0 Answers