so happy about it, just spent hours trying to find what’s wrong with the code and tried a lot of random solutons until it worked
here’s the script if there’s anyone interested, and i’ll appreciate any feedback to improve on it.
first you have to make the moveinput variable public in the PlayerMovement script,
then just copy this code to the bullet script(it’s called orb in my case):
public class orb : MonoBehaviour
{
[SerializeField] float orbSpeed = 20f;
Rigidbody2D orbRigidbody;
PlayerMovement player;
CapsuleCollider2D orbCollider;
float xDirection;
Vector2 orbAimInput;
bool playerHasHorizontalSpeed;
bool playerHasVerticalSpeed;
void Start()
{
orbRigidbody = GetComponent<Rigidbody2D>();
player = FindObjectOfType<PlayerMovement>();
xDirection = player.transform.localScale.x;
orbAimInput = player.moveInput;
if(xDirection>0)
{
transform.Rotate(0f,0f,orbAimInput.y*90f);
return;
}
transform.Rotate(0f,0f,-orbAimInput.y*90f);
transform.localScale = new Vector2 (-xDirection, 1f);
}
void Update()
{
playerHasHorizontalSpeed = Mathf.Abs(orbAimInput.x)>Mathf.Epsilon;
playerHasVerticalSpeed = Mathf.Abs(orbAimInput.y)>Mathf.Epsilon;
if(playerHasHorizontalSpeed)
{
orbRigidbody.velocity = new Vector2 (orbAimInput.x*orbSpeed, orbAimInput.y*orbSpeed);
return;
}
if(playerHasVerticalSpeed)
{
orbRigidbody.velocity = new Vector2 (orbAimInput.x*orbSpeed, orbAimInput.y*orbSpeed);
return;
}
else if(!playerHasHorizontalSpeed && !playerHasVerticalSpeed)
{
orbRigidbody.velocity = new Vector2 (Mathf.Sign(xDirection)*orbSpeed, 0f);
}
}
}
then the rest are just the ontrigger and oncollision lines the same as what is in the lecture.