- Home /
Question by
GamerBot · Mar 18, 2014 at 10:23 PM ·
shootingprojectiledirections2d-sidescroller
How can I shoot at enemies while facing left and right?
Hello. I been trying to have my character to fire spheres at enemies in a 2d platform game. I only can fire the spheres at the right direction. Can someone help me why is it happening, and how to solve it?
enter code herevar prefabBullet:Rigidbody;
var shootForce:float;
var shootPosition:Transform;
function Update()
{
if(Input.GetKey(KeyCode.S))
{
var instanceBullet = Instantiate(prefabBullet, transform.position, shootPosition.rotation);
instanceBullet.rigidbody.AddForce(shootPosition.right * shootForce);
Destroy(instanceBullet,2);
}
instanceBullet.velocity = transform.TransformDirection (Vector3.right * 10);
}
Comment