Movement and Control Problems with understanding

Hi all! :slight_smile:
I want to make a game like Contra3/Metalslug. Classic 2D Sidescrolling Run&Gun Action.

You can shoot in 8 directions in games like this (Left, Right, Up, Down, Upright, Downright, Upleft and Downleft) In this games the left joystick is for both, facing direction and moving at the same Time (I don“t mind moving with the left joystick and facing direction with the right one.

Right now I am able to walk and shoot left and right. Kinda… not what I wanted to do.

I searched for like a week now. Every link is purple and the next time I see Top Down Shooter Movement in my google feed I“m gonna throw my pc into the trashcan haha. Apparently I am searching for the wrong stuff (At least I hope so?)

  1. How can you make a bullet from a Spawnpoint attached to the player movein the same direction as the player is facing?

  2. How do velocity, rotation and movement in general work?

Suggestions or even a slight hint at where and how to start would be great. I“d be grateful for tutoriallinks or some small script example to get an idea of how stuff works,
Thanks in regards,
Dominik!

the bullets should be coming out of a object connected to the player so when he moves it will also move
most likely it will be attached to the player as a child. check parent -child relationship this will work for you

but you have to adjust player to move in those positions first
can u post what code u have so far for the player and shooting

I managed to screw up posting the code didn“t I? Somehow this forums run very slow in my browser.

Example 2:

//PlayerMovement and instantiating the projectile

public class PlayerController : MonoBehaviour {
public float maxSpeed;

private Rigidbody2D myRB;

private bool facingRight;

public Transform FirePoint;
public GameObject bullet;

// Use this for initialization
void Start () {
	myRB = GetComponent<Rigidbody2D>();

	facingRight = true;

}

// Update is called once per frame
void Update () {

	if (Input.GetAxisRaw("Fire1") >0) fireRocket();

	float move = Input.GetAxis("Horizontal");

	myRB.velocity = new Vector2(move*maxSpeed, myRB.velocity.y);

	if(move>0 && !facingRight)

	{
		flip();

	} else if (move <0 && facingRight)

	{
	flip();
  }

}

void flip()

{
	facingRight=!facingRight;
	Vector3 theScale = transform.localScale;
	theScale.x *= -1;
	transform.localScale = theScale;

}

void fireRocket()

{
	if(facingRight)

	{
		Instantiate(bullet, FirePoint.position, Quaternion.Euler (new Vector3 (0,0,0)));

	}else if (!facingRight)

	{
		Instantiate(bullet, FirePoint.position, Quaternion.Euler (new Vector3 (0,0,180f)));
	}

}

}

//Projectile

public class Projectile : MonoBehaviour {
public float rocketSpeed;

Rigidbody2D myRB;
// Use this for initialization
void Awake () {
	myRB = GetComponent<Rigidbody2D>();
	if(transform.localRotation.z>0)
		myRB.AddForce(new Vector2(-1,0) * rocketSpeed, ForceMode2D.Impulse);
	else myRB.AddForce(new Vector2(1, 0) * rocketSpeed, ForceMode2D.Impulse);
}

// Update is called once per frame
void Update () {

}

}

According to your answer, I guess the best thing to do is to work with facing direction bools for like every single direction? (8 since I want to instantiate the projectile basically in 45 degrees for every direction)

By calling a parent you mean, the Child (firePoint in my case) would be moving with the direction the player is facing? Would be great, if that worked out.
Apparently, I canĀ“t even manage to make my character ā€œlookā€ Up and down as of now.

I probably don“t fully understand the whole direction Concept of Unity.

The second thing I don“t get about this is, how do I make my character move in the correct direction, to recognize, which angle should be used for the projectile to fire?

If something is unclear, pls ask. I know, this got fuzzy. Especially since I posted 2 Codes at once. I would be supergrateful if one thing worked out. I think, I get something terribly wrong with directions and parenting stuff/facing directions.

Thanks for your answer!