Hi there,
I have a script that works something like this for the iOS.
var grenadePF : GameObject; ///prefab used to instantiate.
var grenade : GameObject; //remains empty in inspector.
function Update ()
{
if (Input.touchCount == 1)
{
if(Input.GetTouch(0).phase == TouchPhase.Began)
{
grenade = Instantiate(grenadePF, bulletPos, transform.rotation); // create bullet clone
}
if(Input.GetTouch(0).phase == TouchPhase.Ended)
{
grenade.rigidbody.AddForce(Vector3(proDir.x, proDir.y, 0.0) * (speed * proDirDistance) * 0.002, ForceMode.Impulse);
}
}
}
the problem is, and I am quite sure I know why, but unsure how to fix it. The problem is, each time I create and lauch a new genade, I am either taking a grenade that already exists, or somehow the impulse power I am adding is additive, so regardless if the new grenade I am using is new or not, the speed at which the grenade launches gets faster and faster and faster.
So I need to know, how do I use a var grenade : GameObject best so that it’s impulse power is singular, and is not added up?
Essentially, how do I prevent the impulse power from passing to brothers of the same instantiated object?