Hello (First post on this forum! Woot!) I am having an issue with launching a projectile after just reading through the FPS shooter walk through. The projectile launches just fine, except it won’t accept the speed setting if it’s a variable. It will accept me entering in the number raw, but that’s all. I will post the different codes I’ve tried. The “* -1” at the end is because the model I’m using was backwards, so I have to reverse the directions on everything.
var projectile:Rigidbody;
var tspeed = 125;
function Update()
{
if (Input.GetButtonDown("Fire1"))
{
var instantiatedProjectile:Rigidbody = Instantiate(projectile,transform.position,transform.rotation);
instantiatedProjectile.velocity = transform.forward * tspeed * -1;
Physics.IgnoreCollision(instantiatedProjectile.collider,transform.root.collider);
}
}
var projectile:Rigidbody;
var tspeed = 125;
var vspeed = new Vector3(0,0,0);
function Update()
{
if (Input.GetButtonDown("Fire1"))
{
var instantiatedProjectile:Rigidbody = Instantiate(projectile,transform.position,transform.rotation);
vspeed = Vector3(0,0,tspeed);
instantiatedProjectile.velocity = transform.TransformDirection(vspeed);
Physics.IgnoreCollision(instantiatedProjectile.collider,transform.root.collider);
}
}
var projectile:Rigidbody;
var tspeed = 200;
function Update()
{
if (Input.GetButtonDown("Fire1"))
{
var instantiatedProjectile:Rigidbody = Instantiate(projectile,transform.position,transform.rotation);
instantiatedProjectile.velocity = transform.TransformDirection(Vector3(0,0,tspeed));
Physics.IgnoreCollision(instantiatedProjectile.collider,transform.root.collider);
}
}
the only one that’s worked is the following.
var projectile:Rigidbody;
function Update()
{
if (Input.GetButtonDown("Fire1"))
{
var instantiatedProjectile:Rigidbody = Instantiate(projectile,transform.position,transform.rotation);
instantiatedProjectile.velocity = transform.forward * 125 * -1;
Physics.IgnoreCollision(instantiatedProjectile.collider,transform.root.collider);
}
}
If someone could help explain why the projectile won’t accept the variable so I can fix the error, that would be great, thank you.