Question by
moniquetmurphy93 · Apr 22, 2021 at 09:09 PM ·
2dshootingshooter
Shooting mechanic - can't shoot left and right,2D shooting mechanic - can't shoot lift and right
Hi all,
I'm coding a simple 2D shooter, however having loads of issues. When shooting, ammo only goes to the right. and when I move the character, the shot ammo teleport's to different part of the X Axis. I'm at a loss. Any help would be appreciated.
Player Code
{
public GameObject maskToss;
public Transform throwPoint;
public bool hasMasks = false;
void Update()
{
if (Input.GetButtonDown("Fire1"))
{
maskThrow();
}
}
void maskThrow()
{
if (!hasMasks)
return;
MaskPickUpDisplay.maskAmount -= 1;
Instantiate(maskToss, throwPoint);
}
Bullet Code
{
public float speed = 10f;
public Rigidbody2D maskRB;
public GameObject thrownMask;
public float lifetime = 1f;
// Start is called before the first frame update
void Start()
{
Destroy(thrownMask, lifetime);
}
// Update is called once per frame
void FixedUpdate()
{
maskRB.velocity = transform.right * transform.localScale.x * speed;
}
private void OnTriggerEnter2D(Collider2D collision)
{
if (collision.gameObject.tag.Equals("Enemy"))
{
Destroy(gameObject);
}
}
}
Comment