NEED HELP! Shooting an item in the direction the player is facing (up, down, left, right)

Hello so I’m trying to get this throwing axe to be shot from the Firepoint object that is a child of my player. but currently its only shooting right when I press (E) please someone help me!

Here is my PlayerController script and the ThrowingAxe script:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerController : MonoBehaviour {
public float moveSpeed;
private float currentMoveSpeed;
public float diagonalMoveModifier;

private Animator anim;
private bool playerMoving;
private Vector2 lastMove;
private Rigidbody2D myRigidbody;
private static bool playerExists;
private bool attacking;
public float attackTime;
private float attackTimeCounter;
public string startPoint;
public Transform firePoint;
public GameObject throwingAxe;
// Use this for initialization
void Start () {
anim = GetComponent();
myRigidbody = GetComponent();
if(!playerExists)
{
playerExists = true;
DontDestroyOnLoad(transform.gameObject);
} else {
Destroy(gameObject);
}
}

// Update is called once per frame
void Update () {
playerMoving = false;
if (!attacking)
{
if (Input.GetAxisRaw(“Horizontal”) > 0.5f || Input.GetAxisRaw(“Horizontal”) < -0.5)
{
//transform.Translate(new Vector3(Input.GetAxisRaw(“Horizontal”) * moveSpeed * Time.deltaTime, 0f, 0f));
myRigidbody.velocity = new Vector2(Input.GetAxisRaw(“Horizontal”) * currentMoveSpeed, myRigidbody.velocity.y);
playerMoving = true;
lastMove = new Vector2(Input.GetAxisRaw(“Horizontal”), 0f);
}
if (Input.GetAxisRaw(“Vertical”) > 0.5f || Input.GetAxisRaw(“Vertical”) < -0.5)
{
//transform.Translate(new Vector3(0f,Input.GetAxisRaw(“Vertical”) * moveSpeed * Time.deltaTime, 0f));
myRigidbody.velocity = new Vector2(myRigidbody.velocity.x, Input.GetAxisRaw(“Vertical”) * currentMoveSpeed);
playerMoving = true;
lastMove = new Vector2(0f, Input.GetAxisRaw(“Vertical”));
}
if (Input.GetAxisRaw(“Horizontal”) < 0.5f && Input.GetAxisRaw(“Horizontal”) > -0.5f)
{
myRigidbody.velocity = new Vector2(0f, myRigidbody.velocity.y);
}
if (Input.GetAxisRaw(“Vertical”) < 0.5f && Input.GetAxisRaw(“Vertical”) > -0.5)
{
myRigidbody.velocity = new Vector2(myRigidbody.velocity.x, 0f);
}
if (Input.GetKeyDown(KeyCode.Q))
{
attackTimeCounter = attackTime;
attacking = true;
myRigidbody.velocity = Vector2.zero;
anim.SetBool(“Attack”, true);
}
if (Mathf.Abs (Input.GetAxisRaw(“Horizontal”)) > 0.5f && Mathf.Abs(Input.GetAxisRaw(“Vertical”)) > 0.5f)
{
currentMoveSpeed = moveSpeed * diagonalMoveModifier;
} else {
currentMoveSpeed = moveSpeed;

if(Input.GetKeyDown(KeyCode.E))
{
Instantiate(throwingAxe, firePoint.position, firePoint.rotation);

}
}

}
if(attackTimeCounter > 0)
{
attackTimeCounter -= Time.deltaTime;
}
if(attackTimeCounter <= 0)
{
attacking = false;
anim.SetBool(“Attack”, false);
}
anim.SetFloat(“MoveX”, Input.GetAxisRaw(“Horizontal”));
anim.SetFloat(“MoveY”, Input.GetAxisRaw(“Vertical”));
anim.SetBool(“PlayerMoving”, playerMoving);
anim.SetFloat(“LastMoveX”, lastMove.x);
anim.SetFloat(“LastMoveY”, lastMove.y);
}
}

And my throwing axe script is here:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ThrowingAxe : MonoBehaviour {
public float speed;
public PlayerController player;
// Use this for initialization
void Start () {
player = FindObjectOfType();
if (player.transform.localScale.x < 0)

speed = -speed;
}

// Update is called once per frame
void Update () {
GetComponent().velocity = new Vector3(speed, GetComponent().velocity.y);

}
void OnTriggerEnter2D(Collider2D other)
{
Destroy(gameObject);
}
}

Please help, been stumped for days now. even watched videos and nothing has fixed the problem!

Please refer to this page for how to post code nicely on the forums: Using code tags properly - Unity Engine - Unity Discussions

Have you confirmed that your player object is found correctly in your second script?

If you do not need drag or gravity, you can simply set the velocity once, after you adjust the speed, and avoid resetting it every update (should have the same effect).

I tested the basic notion of this script and it’s working for me { left + right }.

it wont shoot right for me for some reason it only shoots left no matter what

Not sure what is wrong. Is the speed always negative no matter what?

I’m trying to just have it shoot straight, no gravity and once it collides with another collider her does a /destroy, but when my character faces left and I press [E] it still shoots right. idk what to do :\

Can you attach a simple package to the thread? I’d look at it for you to try to help you solve it.

I sent you a conversation request I believe

Ya, I got it… I’ll try to help you out.