- Home /
ridgidbody 2d update rate?
Hey guys, So im trying to create a game where every 2 seconds a crate will spawn and move along a set route, Once the user clicks it drops the crate. The aim is to stack the crates as high as possible.
My issue is that ive got the game spawning prefabs and they drop properly etc. However every other crate will have gravity scale turned to 1; so instead of moving across the screen it drops without the user telling it too.
The initial velocity and Drop scripts are on the prefab while the spawn script is on a empty game object
Is this the right way to do this? or is there a better way.
// Initial Velocity Script - gets the crate moving
public Vector3 initVel;
// Use this for initialization
void Start () {
this.rigidbody2D.AddForce = initVel;
}
}
// Spawn Script.
public float SpawnDelay = 3;
public GameObject CratePrefab;
public GameObject Spawnpoint;
// Use this for initialization
void Start() {
InvokeRepeating ("InstantiateCrate", SpawnDelay, SpawnDelay);
}
void InstantiateCrate()
{
Instantiate(CratePrefab, Spawnpoint.transform.position, Spawnpoint.transform.rotation);
CratePrefab.rigidbody2D.gravityScale = 0;
CratePrefab.rigidbody2D.isKinematic = false;
}
// Update is called once per frame
void Update () {
}
}
// Drop Script (some parts not working yet)
public GameObject cratePrefab;
public bool IsLanded = false;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if(Input.GetMouseButtonDown(0) && IsLanded == false)
{
StopCrate();
DropCrate();
}
}
void StopCrate()
{
Debug.Log ("STOP CRATE");
this.gameObject.rigidbody2D.isKinematic = true;
this.gameObject.rigidbody2D.velocity = Vector2.zero;
}
void DropCrate()
{
Debug.Log ("DROP CRATE");
this.gameObject.rigidbody2D.isKinematic = false;
this.gameObject.rigidbody2D.gravityScale = 1;
}
void OnTriggerEnter2D (Collider2D other)
{
IsLanded = true;
Debug.Log ("LANDED");
}
}
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Instantied 2D Prefab Is Invisible 1 Answer
Problem with mobs 0 Answers
GetComponent().enabled = true; 1 Answer
How do I assign a prefab to a variable with a script? 1 Answer