- Home /
Instantiating two rigidbody at a time
Just making a simple game where i am meant to instantiate a single rigidbody and make it travel forward from where it spawns in, instead it instantiates two rigidbodys and doesnt travel forward at all.
public Rigidbody laser;
public GameObject LaserSpawn;
private float fireRate = 0.65f;
private float shotReady;
private float velocity = 50f;
void Start () {
}
void Update () {
if(Input.GetKeyDown (KeyCode.Space) && Time.time > shotReady)
{
shotReady = Time.time + fireRate;
GameObject laserShot = Instantiate(laser, LaserSpawn.transform.position + LaserSpawn.transform.forward, laser.transform.rotation)as GameObject;
laserShot.rigidbody.AddForce(laserShot.transform.forward * velocity, ForceMode.Impulse);
}
}
}
any help will be much appreciated
Did you drag laser
from the Hiearchy area or from the Assets area?
Is the drag set to 0 or appropriately low in the inspector?
Answer by ramp · Jan 21, 2015 at 01:03 PM
Hello,
Use Rigidbody instead of GameObject,like this may be help.
Rigidbody laserShot = Instantiate(laser, LaserSpawn.transform.position + LaserSpawn.transform.forward, laser.transform.rotation)as Rigidbody;
Thanks
Ram
I'm an idiot and had the script on two things (the player and laserSpawn) all is sorted now
Your answer
![](https://koobas.hobune.stream/wayback/20220613181010im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Orbit problem in 5.0 unity 1 Answer
Rigidody.velocity = Direction * speed; How to get direction? 1 Answer
First person camera judder with rigidbody based characters 1 Answer