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:
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
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;
This also works thanks! (its the same answer really)
What error are you getting? And on what line? An how do you declare 'Bullet'?
– robertbuFirst line of the script: Rigidbody instantiatedBullet = Instantiate(Bullet, WeaponPoint.position, WeaponPoint.rotation); Bullet is a variable of type GameObject
– Borzi