- Home /
Question by
unity_MkBjrQfut7iKHA · Feb 16, 2018 at 05:03 PM ·
velocityinstantiate prefab
Can't addforce to instantiated object
So I have code that was working over but now does not work. Everytime I click and I have a boolean set to when I pick up ammunition, in this case just a ball, it sets it to true so you can fire. When you fire the AddForce is supposed to fire with variables I have set in the gameObject. I have the ball(Projectile) Set to isKinematic because it errors otherwise.
public bool hasBall = false;
private Rigidbody ballInstance;
public Transform gunTip;
Rigidbody otherBall;
public Rigidbody obj;
public float ballSpeed;
//private bool isAlive = false;
public AudioClip audioClip;
AudioSource audioSource;
void Start()
{
audioSource = GetComponent<AudioSource>();
}
void FixedUpdate()
{
// If the left mouse button is pressed down...
if (Input.GetMouseButtonDown(0) && GameObject.FindWithTag("Player").GetComponent<PlayerController>().hasBall == true)
{
GameObject.FindWithTag("Player").GetComponent<PlayerController>().hasBall = false;
ballInstance = Instantiate(obj, gunTip.position, gunTip.rotation) as Rigidbody;
ballInstance.AddForce(gunTip.forward * ballSpeed);
audioSource.PlayOneShot(audioClip, 0.7f);
}
}
}
Comment
Your answer

Follow this Question
Related Questions
taking velocity of object a to apply to an instantiated shattered object. 1 Answer
Velocity powered rigidbody on a moving platform without parenting. 3 Answers
want, new instantiated prefab to keep velocity of old, (now destroyed) instantiated prefab. 1 Answer
no velocity/force after build unity4 JS 0 Answers
Constant force motion: s = s0 + v0 * t + a0 * t * t. Why? 1 Answer