Hey guys I have a infinite, horizontally scrolling platform that gets gaps in it when it is instantiated. I believe its because of the frame rate or something of that nature. Can someone suggest a way of doing this without getting gaps in the platform.
var groundPiecePos : Transform;
var groundPieceClone : Transform;
function FixedUpdate()
{
groundMaker();
levelScroll = GetComponent(GameMain);
levelScroll.levelScroll();
}
function groundMaker ()
{
if (groundPiecePos.position.x < -20)
{
Destroy(gameObject);
var groundPieceInst = Instantiate (groundPieceClone, Vector3(20,0,0), Quaternion.identity);
groundPieceInst.name = "Ground";
}
}
I imagine that even under the best of circumstances it might be difficult to get the edges of the platforms to match exactly (that is, with no rendering artifacts), but I think you can probably improve on your current method somewhat.
This is untested, but here’s what I’d probably try first:
function groundMaker ()
{
if (groundPiecePos.position.x < -20)
{
var x = groundPiecePos.position.x + 40;
Destroy(gameObject);
var groundPieceInst = Instantiate (
groundPieceClone, Vector3(x,0,0), Quaternion.identity);
groundPieceInst.name = "Ground";
}
}
Assuming all the ground pieces are moving at exactly the same rate, this should cause newly instantiated ground pieces to be positioned correctly with respect to the existing pieces. (Again though, this is untested.)