- Home /
What is this variable type?
Hey, I am trying to convert a script into C# which sends a bullet along the raycast. Anybody know what the variable type is that is throwing up errors here?
//Instantiate the Bullet
Rigidbody instantiatedBullet = Instantiate(Bullet, WeaponPoint.position, WeaponPoint.rotation);
//Set the position on where it has to go and how quickly
instantiatedBullet.velocity = (Hit.point - transform.position).normalized * muzzleVelocity;
//Make it go in the right direction
instantiatedBullet.rotation = Quaternion.LookRotation(instantiatedBullet.velocity);
Original Script: http://answers.unity3d.com/questions/129516/shoot-bullet-along-the-ray-cast.html
What error are you getting? And on what line? An how do you declare 'Bullet'?
First line of the script:
Rigidbody instantiatedBullet = Instantiate(Bullet, WeaponPoint.position, WeaponPoint.rotation);
Bullet is a variable of type GameObject
Answer by Subhajit-Nath · Nov 29, 2013 at 05:56 PM
Try this one >>>
Rigidbody instantiatedBullet = Instantiate(Bullet, WeaponPoint.position, WeaponPoint.rotation) as Rigidbody;
Answer by GameVortex · Nov 29, 2013 at 05:56 PM
You have not specified what error you are getting but I am guessing you are getting an error on the first line. The Instantiate function returns an object, you would most likely want to cast that object into the type the prefab is. If your prefab is a rigidbody you can do it like this:
Rigidbody instantiatedBullet = Instantiate(Bullet, WeaponPoint.position, WeaponPoint.rotation) as Rigidbody;
Your answer
![](https://koobas.hobune.stream/wayback/20220613123052im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Clicking on an Object to Make it the Variable Target 1 Answer
Need Help with Bullets 1 Answer
Velocity powered rigidbody on a moving platform without parenting. 3 Answers
Best way to shoot physical bullets? 2 Answers
Raycasr in my fps? 1 Answer