Spawn Points not moving with player on the Y-axis.

Hey,

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

Im not to great in C# but I got the basics of what you mean.

Here is the random generating script :

    #pragma strict

     

    var spawnPoint1 : Transform;

    var spawnPoint2 : Transform;

    var spawnPoint3 : Transform;

    var cloud : GameObject;

    var cloudType = 3;

     

    function Start () {

        InvokeRepeating("CreateCloud", 1, 1.7);

    }

 

    function CreateCloud() {

        cloudType = Random.Range(1,4);

       

        print(cloudType);

       

        switch (cloudType) {

        case (1) :

        Instantiate (cloud, spawnPoint1.position, Quaternion.identity);

        break;

       

        case (2) :

        Instantiate (cloud, spawnPoint2.position, Quaternion.identity);

        break;

       

        case (3) :

        Instantiate (cloud, spawnPoint3.position, Quaternion.identity);

        break;

    }
}

EDIT : Actually that script is fairly easy to translate. Ill give it a try a re comment on this.

I understand what is happening but dont know what do you want to happen.
Can you post a diagram of how you want the clouds to spawn as this will help,

1523666--87412--$Screen shot 2014-02-17 at 1.03.57 PM.png

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.

spawn clouds on the same x value at the same time at different y values

Not sure what you mean, same x value as what and the same time as what.

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.

Heres a picture :

1523760--87426--$Screen shot 2014-02-17 at 2.22.32 PM.png

did you get the C# code i posted to work after you translated it to js

You could still use your switch case system but you spawn 2 or however many clouds you want,

Say you want 2 clouds then you spawn 1 cloud at x,y,z and the other cloud at x+small random range, y+ whatever you want and z

Well I was thinking of putting the minimum x value pretty small but i need to make it so the 2 wont be colliding with each other

I thought you was wanting to spawn similar x value but different y value, now I dont know what you want again.

Have you tried any new code yet.

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.

you can decide the minimum x value you want and then use if x<= minimumvalue then y=y+something

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.