mardi 11 décembre 2018

How to add different gravity on spawning objects?

Im working on a project that I want to create a power up effect whenever the button "Q" is pressed, I have the animation working and the character, I also have the spawning objects around my player that I want to spawn (See Figure below) enter image description here My question is how to add different gravity on each rock (spawning object).

Here is the script that I'm currently using.

/* Public Variables Declaration */
public Transform spawn_LocationForSmall;
public Transform spawn_LocationForMedium;
public Transform spawn_LocationForLarge;
public GameObject smallRock_Prefab;
public GameObject mediumRock_Prefab;
public GameObject largeRock_Prefab;

/* Private Variables Declaration */
private GameObject[] smallRocks_List;
private float posX, posY, posZ;

private bool smallCount = false;
private bool mediumCount = false;
private bool largeCount = false;

private bool small_CheckPos = false;
private bool medium_CheckPos = false;
private bool large_CheckPos = false;




void Start() {

    //smallRocks_List = GameObject.FindGameObjectsWithTag("smallRock");

    Create_Small_Rocks();

    Create_Medium_Rocks();

    Create_Large_Rocks();


}

 private void Create_Small_Rocks(){

    for(int i=0; i<=20; i++){

        small_CheckPos = false;
        posX = this.transform.position.x + Random.Range(-3.0f, 3.0f);
        posY = this.transform.position.y + Random.Range(-3.0f, 3.0f);
        posZ = this.transform.position.z + Random.Range(-3.0f, 3.0f);

        if(posX > 3f && posY > 3f){

            small_CheckPos = true;
        }

        if (small_CheckPos == true) {

            Vector3 newPos = new Vector3(posX, posY, posZ);

            GameObject createdObject = GameObject.Instantiate(smallRock_Prefab, 
                newPos, spawn_LocationForSmall.rotation) as GameObject;

            createdObject.transform.parent = spawn_LocationForSmall.transform;
        }

    }
    smallCount = true;
}
 /* the other two functions are similar to this */




Aucun commentaire:

Enregistrer un commentaire