I have 3 spawn points as children of my player that follow him around 15 meters in front of the player to spawn new platforms but the spawn points follow the player up when he jumps so the platforms can technically be spawned higher and higher and not stay on the same three levels like I wanted. I’ve tried adding rigidbodys out of desperation and locking there rotations and y values but obviously that didn’t work.
I have several scripts on the player but I don’t know which one would be the most helpful in this situation :
I have a player move script
an auto jump script when it hits the platforms
and a Random Platform Generator for the platforms to be generated.
Comment back on this thread and tell me what script you would need to see.
Also on a side note I could also use help on destroying the platforms that the player has already past and is out of sight to reduce lag and data usage.
Show this Random Platform Generator for the platforms to be generated
You may not need the 3 child objects anyway.
You can set the distance infront of the player to spawn by setting it in the Start()
spawnPositionX =Mathf.RoundToInt (transform.position.x + 25f); //Distance from player to spawn here it is 25 world units
You could easily do the same for the Y and Z position as well.
Just declare some variables:
private float spawnPositionX; //X spawn position
private float spawnPositionY; //Y spawn position
private float addToPositionY; //The amount we add to the y position
Then just create the thing you want like:
void CreateThing()
{
//If spawnPositionX is less the player position + 15
if (spawnPositionX < transform.position.x + 15)
{
spawnPositionX+=Random.Range(10.5f,12f);
spawnPositionY = Random.Range(-5,5);
Instantiate(thing,new Vector3(spawnPositionX,spawnPositionY,0),Quaternion.identity);
}
}
And just call the create method in Update()
CreateThing();
The above code will need to be attached to the player
That is basicly what I want but I also want clouds to spawn on the same x value so I can have the player jump off of either one. What it was doing with the script was that it would spawn the first one correct and then start spawning them right after one another.
Also how could I destroy the platforms when they pass off the camera on teh left side of the screen.
Also another bug is when the player hits the ground and respawns it stops spawning the platforms.
Here is the script I translate :
#pragma strict
var spawnPositionX : float;
var spawnPositionY : float;
var cloud : GameObject;
function Start(){
spawnPositionX = Mathf.RoundToInt (transform.position.x + 5);
}
function Update(){
CreateCloud();
}
function OnCollisionEnter(myCol : Collision){
if(myCol.gameObject.tag == "fallout"){
spawnPositionX = 0;
spawnPositionY = 0;
}
}
function CreateCloud(){
if (spawnPositionX < transform.position.x + 14)
{
spawnPositionX += Random.Range(7,10);
spawnPositionY = Random.Range(5,10);
Instantiate(cloud,new Vector3(spawnPositionX,spawnPositionY,35),Quaternion.identity);
}
}
Here is my respawn script :
var Cloud : GameObject;
var gameObjects : GameObject[];
function OnCollisionEnter(myCol: Collision){
if(myCol.gameObject.tag == "Player"){
GameObject.Find("Player").transform.position = Vector3(-4, 8, 35);
GameObject.Find("Main Camera").transform.position = Vector3(-0.7, 5.8, 12);
gameObjects = GameObject.FindGameObjectsWithTag ("cloud");
for(var i = 0 ; i < gameObjects.length ; i ++)
Destroy(gameObjects[i]);
}
}
is this an endless runner type thing or can the player stop / go left ( - x direction)
The way I deleted objects that had passed the camera was to put a script on the object that checks if the object is whatever past the player and destroys itself
if(this.transform.position.x < (Player.Instance.transform.position.x-15f))
Destroy(this.gameObject); // destroy obstacle when so far past player
I think you would have to do something like when the cloud is created you find the player and then check its position like:
GameObject.Find(“Player”).transform.position.x-15f
Ahh that makes sense and ya its a continuous runner and I fixed the spawning issues but now I just need it to spawn clouds on the same x value at the same time at different y values. That picture does not show that but my idea needs something like that.
I mean that instead of having platforms be spawned like this _ _ - where they only spawn 1 every so meters. I want them to be spawning like 2 on the same x value on top of each other. They need to have different y values and I don’t want this happening every time and they can’t be the exact same x value. They need to be alittle spread apart.
Ok so do u know my code that i translated. The random range of the x value i was goin to put very low so that every once and awhile it will spawn them close together. But if i do that they might have a similar y value which means they would collide. How can I make it so when the x is small the height difference has to be big.
I tried that out but my problem was that when I did that then sometimes the y value + 4 for example would be the same as the object I had spawned in the last x value. So pretty much my problem is that when i spawn a cloud in the minimum value it takes a random y value and adds 4 to it so sometimes it works and then sometimes it still collides.